WIll GC.Collect() immediately collect garbage ?

  • Thread starter Thread starter chak
  • Start date Start date
C

chak

WIll GC.Collect() immediately start a GC thread and clear all unreferenced
objects from the heap ?

Regards,

Chak.
 
yes but:

you can choose a partial collect with Collect( int generation)
usually GC starts automatically when memory is low
use Collect() only if you are sure it increase performances

it's intersting to start GC before a critical action where max memory is
needed, ie :
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();

Nicolas Guinet
 
Back
Top