Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get memory (ram) used by specific variables in Visual Studio

I'm finishing up a project, but there seem to be something which is using too much memory. I think there's something that isn't being disposed. And since my program has a LOT of code, I don't feel like going through everything.. There must be a way to see what variable is using what amount of memory during runtime?

like image 252
Tokfrans Avatar asked Oct 29 '25 00:10

Tokfrans


1 Answers

You can look at the managed memory using a debugger such as WinDbg with the SOS extension.

Attach to your process, load SOS using the .loadby sos clr command and inspect the heap using the !dumpheap -stat command. That will tell you the number and type of objects on the heap. From there you can figure out if any of these are taking up more memory than you expected.

This question has relevant information as well.

like image 174
Brian Rasmussen Avatar answered Oct 31 '25 16:10

Brian Rasmussen