Friday 15 February 2013

.net - How can I determine if a delegate is an anonymous lambda? -


We have a library that mimics the event and provides some enhanced functionality. It is mainly used by registered representatives By keeping track of. Like events, there is memory leak capability in it.

I am changing the class, which connect the delegates using weaker references to managers, but I am running into a problem: if you register an anonymous lambda and GC . Collect Representative gets accumulated I want to schedule the program whether a representative is registered, it is an unknown lambda and use a strong reference for that matter.

Question: How can I determine if a representative is an unknown lambda (or more generally, some words that we would not expect it to be 'disappeared') .

One way to work is if representative. Goal property is zero, but it normally captures steady methods, so what I want to do. The second option is that the IsSpecialName and IsStatic are set to the right on the property or the representative result .

One concern is that if I had recorded the strong reference of Lambidas using members of the square, then we would still end with the same memory - the leak scenario ... or we Using a Dealted Object Can It Have a Great Way to Handle?

Actually, you can not do the anonymous Lambda Methods You Can Examine the Method Name:

  Fixed Ent Fu () {Return 0; } Zero main () {Func & lt; Int & gt; Foo = Foo; & Lt; Integer & gt; Bar = () = & gt; 0; Console.WriteLine (foo.Method.Name); // Foo Console WrightLine (bar.Method.Name); // & lt; Main & gt; B__0}   

This is a very bad approach, but this may be the only way because foo and bar are otherwise unenviable.

No comments:

Post a Comment