Garbage collector

  • Thread starter Thread starter Pravin Shrirao
  • Start date Start date
Yes (GC.Collect). But without a very good reason, you should not interfere
with the GC.
 
-----Original Message-----
Can we call garbage collector explicitly in .nert
framework?


.

Yes, just call GC.collect(gen). This collect generations 0
to gen where gen <= 2, there are 3 generations supported
in current version of the framework. You can also call
GC.collect() without arguments, this is eqivalent to
GC.collect(GC.maxGeneration). You shouldn't make any
assumptions about when Your finalize() method will start
working, and about the order of execution of finalize()
methods, because the F-Reachable queue is processed by a
separate thread and is completely non-deterministic.
Anyhow, You can use
GC.WaitForPendingFinalizers() method to block the current
thread and wait until the F-Reachable queue is processed.
GC.collect()
GC.WaitForWaitingFinalizers()
GC.collect()
Try to implement IDisposable interface instead of a
Finalize() method when possible.
Look for "GC class" in MSDN.
 
-----Original Message-----
Can we call garbage collector explicitly in .nert
framework?


.
Yes, You can Call the GC.Collect method and pass the
object you want to get collected. When this line is
encountered while execution it' suspend all the running
threads and give the CPU slot to garbage collector to
execute.

(e-mail address removed)
 
Back
Top