Skip to content

[Proposal]: Weak keyword better memory managment #4039

Discussion options

You must be logged in to vote

Just because it hasn't been explained a lots of detail yet, it's worth highlighting that anonymous delegates / lambdas make the whole concept of weak events really rather tricky.

Let's take a very simple example:

public class C
{
    void Run()
    {
        var list = new List<object>();
        Func<bool> action = () => list.Count > 0;
    }
}

If you take a look at the generated code:

public class C
{
    [CompilerGenerated]
    private sealed class <>c__DisplayClass0_0
    {
        public List<object> list;

        internal bool <Run>b__0()
        {
            return list.Count > 0;
        }
    }

    private void Run()
    {
        <>c__DisplayClass0_0 <>c__DisplayClass0_ = new <>

Replies: 5 comments 16 replies

Comment options

You must be logged in to vote
6 replies
@HaloFour
Comment options

@redradist
Comment options

@HaloFour
Comment options

@redradist
Comment options

@HaloFour
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
8 replies
@redradist
Comment options

@redradist
Comment options

@CyrusNajmabadi
Comment options

@redradist
Comment options

@CyrusNajmabadi
Comment options

Comment options

You must be logged in to vote
1 reply
@redradist
Comment options

Comment options

You must be logged in to vote
1 reply
@sharwell
Comment options

Answer selected by sharwell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants
Converted from issue

This discussion was converted from issue #4039 on October 20, 2020 13:04.