By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

Garbage Collector

P: 10
Does the garbage collector works periodically in C#? If yes, what is the time interval between two activations?
Jan 23 '09 #1
Share this Question
Share on Google+
2 Replies

P: 10
Is GC a part of CLR?
If yes, like CLR is it common to all App Domains?
Jan 23 '09 #2

Expert 100+
P: 750
@gayatri pande
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
You can force GC by
Expand|Select|Wrap|Line Numbers
  1. System.GC.Collect();          
  2.             GC.WaitForPendingFinalizers();
  3.             GC.Collect(1);
  4.             GC.Collect(0);
  5.             GC.WaitForPendingFinalizers();
But it not at all recommended... You need to use standard coding style with wrt to memory management and implementing IDisposable...
Jan 23 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.