Unsubscribed event handlers are one of the biggest real-world leak causes.
publisher.SomeEvent += OnEvent; // stays forever if not removed
⚠ Why It Leaks
-
The publisher holds a reference to your object
-
GC can’t collect your object
-
Memory keeps climbing
✔ The Fix
Always unsubscribe:
publisher.SomeEvent -= OnEvent;
Or use weak events or IDisposable patterns.
💡 Bonus
Use tools like:
-
dotMemory
-
PerfView
-
Visual Studio’s Memory Analyzer
