Screen recording: fixing a C# memory leak in VS Code with the SharpLsp memory profiler, from leak suspects to the retention graph and a verified fix
Read the guide: How to Fix a Memory Leak in C# and .NET
Transcript
This is Storefront, a C# app whose memory keeps climbing. Track Memory on its process, right from VS Code.
SharpLsp snapshots the heap every ten seconds, and the heap keeps growing.
Leak suspects rank by consistent growth. CustomerSession climbs in every snapshot. Click it, and you jump to its code.
So, what's keeping those sessions alive?
The reference graph walks up to the root: a static dictionary that remembers every order, and never forgets one.
The fix: keep the last thousand orders, and evict the oldest as each new one arrives.
Rebuild, run it again, and track memory once more.
This time the heap holds steady, and no suspect climbs past Low. The leak is found, fixed, and proven, without leaving your editor.