3 ms·
The C# compiler does the same thing: http://blogs.msdn.com/b/ericlippert/archive/2007/06/06/fyi-c-and-vb-closures-are-per-scope.aspx http://blogs.msdn.com/b/er
by wingspan 13y ago
The C# compiler does the same thing:
http://blogs.msdn.com/b/ericlippert/archive/2007/06/06/fyi-c-and-vb-closures-are-per-scope.aspx http://blogs.msdn.com/b/ericlippert/archive/2007/06/06/fyi-c...
This is an old article, but I believe it still applies to the latest iteration of the language.
- RyanZAG 13y agoDoes indeed still apply, and is actually formalized into the language spec itself [1] in section 7.15.5.1 Captured outer variables. So it's actually a feature (really) in the case of C#, not a bug. [1] http://www.microsoft.com/en-us/download/details.aspx?id=7029 http://www.microsoft.com/en-us/download/details.aspx?id=7029 "the local variable x is captured by the anonymous function, and the lifetime of x is extended at least until the delegate returned from F becomes eligible for garbage collection (which doesn’t happen until the very end of the program)."
- br1 13y agoI don't see how that part of standard mandates that all anomymous functions share the same closure. The example only has a single lambda.