Does the garbage collector works periodically in C#? If yes, what is the time interval between two activations?
Garbage Collector
Collapse
X
-
Tags: None
-
-
You cannot predict when garbage collection will be called and when its called all managed threads are suspended... There are various generations( 0,1,2 . o is collected first and its very easy for GC to clear Gen0 objects.. As object are referenced for longer they move to higher gen. Higher ther gen more diffcult for GC to clear).. Objects that have longer life( wrt memory) are higher up then objects recently created...
go through the following you will get a clear picture
Garbage Collection
Garbage Collection
MSDN
You can force GC by
But it not at all recommended... You need to use standard coding style with wrt to memory management and implementing IDisposable...Code:System.GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(1); GC.Collect(0); GC.WaitForPendingFinalizers();Comment
Comment