How to create a memory leak in C# / .NET -


possible duplicates:
is possible have memory leak in managed code? (specifically c# 3.0)
memory leak in c#

there similar question on yesterday, java, i'm interested - takes create memory leak in c# / .net (without using unsafe) ?

static events; deadly, since never go out of scope.

static event eventhandler evil;  for(int = 0 ; < 1000000 ; i++)     evil += delegate {}; 

the anonymous method nice-to-have here nice because also pig unsubscribe unless take copy variable/field , subscribe that.

technically isn't "leaked", can still access them via evil.getinvocationlist() - however, when used regular objects can cause unexpected object lifetimes, i.e.

myheavyobject obj = ... ... sometype.somestaticevent += obj.somemethod; 

now object @ obj lives forever. satisfies enough of perceived leak imo, , "my app died horrible death" enough me ;p


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -