"Scott M." <No****@NoSpam.com> wrote
Ok Imran, then let me ask you this...
When the GC does eventually collect the garbage, what determines which
objects are collected and which are not? Is is simply that any object that
is no longer referenced are the ones collected?
Its not quite that simple. The GC is good at cleaning up short lived objects,
but those that hang around for a while get shoved on 'the back burner' (meaning
they don't get tested as often).
The GC is also pretty good at managing those long lived objects, but its the
middle ground that needs to be addressed. That area is dependant on your
own use of memory, so just how often the GC runs, and decides to move
things to the 'back burner' is partially dependant on what you're doing....
FWIW:
The proper term is 'generations'. Generation 0 items come and go as needed....
So, its those Gen 0 items that are swept away when nothing holds a reference
to them. If they survive that first look, then get shoved into the Gen 1 area, and
then Gen 2, etc where they don't go looking for memory as often as the Gen 0 area.
For a bit more on the GC, you might want to watch the .Net show where one
of the CLR's architect was interviewed:
http://msdn.microsoft.com/theshow/Ep...27/default.asp
LFS