Advertisement
Advanced C#, Memory & Garbage Collection

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.

Save C# mock interview
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 -> leak
Real-world example
An ever-growing static dictionary cache slowly exhausts memory in a long-running service.