As i read, the GC method will be called automatically during run time and all the unused object's memory will be deallocated. If everything is done by automatically then what is the use of forcefully calling GC() method.
Asked
Active
Viewed 17 times
0
-
maybe it exists as a debugging tool, if you do wonder why memory use seems high and you call GC without tending to see memory freed, it tends to suggest it is in use somewhere rather than waiting to be collected. Also some circumstance where a program carries out a lengthy amount of processing before becoming inactive, there might be a demand from some people to call a GC, as if to say 'hey you might as well clear up right now' maybe in reality still not the right thing to do - at least people can experiment if it exists though. – Cato Aug 05 '16 at 15:37
-
Perhaps for unmanaged code. – Missy Aug 05 '16 at 15:57
-
Some interfaces require that that a `Dispose` method is implemented, which usually handles the GC. Also, as a fun exercise, you should create some objects and manually call the Garbage Collector. Observe the heap size before the call and after using `GC.GetTotalMemory()`. You will see why calling GC shouldn't be done unless absolutely necessary. – Ingenioushax Aug 05 '16 at 15:57
-
GC is generally separate to .dispose methods. Garbage collection is concerned with the reclamation of managed memory. Dispose is a method that is designed to free unmanaged resources, it doesn't invoke the garbage collection of managed memory items. There is however some advice on the auto-generated vb.net dispose stub to set 'large fields to null' or similar (a question exists here on the value of this advice) – Cato Aug 05 '16 at 16:08