Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call garbage collect in visual studio

Is it possible, to say the gc to collect during debugging session via Visual Studio 2015 Enterprise?

I want to observe the memory usage of my application when calling GC.Collect(), but only for some debugging reasing. So calling it from Visual Studio during debugging the app would be very helpful.

Thank you very much!

like image 944
BendEg Avatar asked Nov 24 '15 22:11

BendEg


People also ask

How do I force garbage collection in Visual Studio?

To force a garbage collection, use the hotkey: Ctrl+Alt+Shift+F12, Ctrl+Alt+Shift+F12 (press it twice). If forcing garbage collection reliably makes your scenario work, file a report through the Visual Studio feedback tool as this behavior is likely to be a bug.

Can you manually call the garbage collector in C#?

You can force garbage collection either to all the three generations or to a specific generation using the GC. Collect() method.

What is garbage collection in Visual Studio?

Garbage collection (GC) is a memory recovery feature built into programming languages such as C# and Java. A GC-enabled programming language includes one or more garbage collectors (GC engines) that automatically free up memory space that has been allocated to objects no longer needed by the program.


2 Answers

You can write GC.Collect() in the Immediate Window.

like image 111
Sievajet Avatar answered Oct 02 '22 22:10

Sievajet


During a breakpoint you can use the "immediate window" to issue commands, just do a GC.Collect()

like image 37
Scott Chamberlain Avatar answered Oct 03 '22 00:10

Scott Chamberlain