Garbage Collector

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gayatri pande
    New Member
    • Jan 2009
    • 10

    Garbage Collector

    Does the garbage collector works periodically in C#? If yes, what is the time interval between two activations?
  • gayatri pande
    New Member
    • Jan 2009
    • 10

    #2
    Garbage Collector

    Is GC a part of CLR?
    If yes, like CLR is it common to all App Domains?

    Comment

    • PRR
      Recognized Expert Contributor
      • Dec 2007
      • 750

      #3
      Originally posted by gayatri pande
      Does the garbage collector works periodically in C#? If yes, what is the time interval between two activations?
      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
      Code:
      System.GC.Collect();          
                  GC.WaitForPendingFinalizers();
                  GC.Collect(1);
                  GC.Collect(0);
                  GC.WaitForPendingFinalizers();
      But it not at all recommended... You need to use standard coding style with wrt to memory management and implementing IDisposable...

      Comment

      Working...