It’s really easy to force Garbage Collector to collect dead objects from heap.
All you need is command:
| |
From Visual Studio during debugging
- As first your application needs to be paused. This can be done when code reaches breakpoint, or you can use
Break Allfunction (Ctrl+Alt+Backor blue pause icon
in toolbar) - When the code is paused, open the
Immediate Window(another tab of Output by default) Write command intoImmediate Windowand pressEnter:
| |
Garbage collection should be performed now and expected result is:
| |
From code during runtime
You should not to care about GC in application – .NET runtime do it instead of you.
But in case you really need it, you can call GC by:
| |