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
Post a Comment