What causes managed memory leaks despite the GC?
Short answer
Objects stay reachable unintentionally: static references, un-removed event handlers, long-lived caches, or captured closures. The GC can't collect what is still referenced.
Advertisement
AModel answer
Objects stay reachable unintentionally: static references, un-removed event handlers, long-lived caches, or captured closures. The GC can't collect what is still referenced.
StaticCache.Add(bigObject); // never removed -> leakReal-world example
An ever-growing static dictionary cache slowly exhausts memory in a long-running service.