I suspect you knew it wasn't that simple a question... the GC collects parts of the managed heap at different frequencies. The heap is partitioned into 3 sections called generations. The idea is that collecting a generation is a lot cheaper than collecting the entire heap.
An object lives in one of the generations depending on its "age". The youngest objects are on generation 0, older ones in generation 1 and the oldest in generation 2. Age is the number of collections that have occurred during this objects lifetime. This algorithm (the ephemeral garbage collector) performs well for the typical application. Its based on the assumption that the newer an object is the shorter it lifetime will be. Conversely the older an object is the longer its lifetime. When an object is newly created it is placed in generation 0. If the collector runs and the object is still in use it is promoted to generation 1. A collection is usually kicked off automatically when each generation hits a threshold limit. Generation 0 is collected much more frequently than generation 1 which is collected much more frequently than generation 2. This is because the heap size triggers of the generations: Typically at AppDomain startup they at: Generation 0: 256 KB Generation 1: 2 MB Generation 2: 10 MB These are tuned at runtime to maximize performance. The GC also runs when you call GC.Collect(int generation) but doing so usually screws with he GC algorithm. A final collection will also run when the AppDomain unloads. Jim > -----Original Message----- > From: Farhan [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, May 01, 2002 3:32 PM > To: [EMAIL PROTECTED] > Subject: [DOTNET] How often does Garbage Collection run? > > > How often does garbage collection run? what condition needs > to be true in > order for it to run? is there any way to tell when the > Garbage collection > will run? > > Thanks, > Farhan > > You can read messages from the DOTNET archive, unsubscribe > from DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.