Heap and Garbage Collection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I was reading this article
(http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx) in MSDN,
written by Jerffrey Richter. He has explained the working of gabage
collection pretty very well.

What is confusing me here is when he talks about heap. He says that garbage
collection must occur when heap fills. Is it different from saying Heap is
full? I remember someon saying that garbage collection will occur when the
heap is full. I only want to know whether the garbage collection occur only
when the heap is full.

Thanks
pradeep_tp
 
| Hi all,
|
| I was reading this article
| (http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx) in MSDN,
| written by Jerffrey Richter. He has explained the working of gabage
| collection pretty very well.
|
| What is confusing me here is when he talks about heap. He says that
garbage
| collection must occur when heap fills. Is it different from saying Heap is
| full? I remember someon saying that garbage collection will occur when
the
| heap is full. I only want to know whether the garbage collection occur
only
| when the heap is full.
|
| Thanks
| pradeep_tp
|

No, GC occurs when the GC heap fills, that is before he is 'full'. The GC is
triggered when a certain Gen0 threshold is reached, the threshold depends on
a number of heuristics, like the size of the CPU L2 cache, the version of
the CLR and can change dynamically depending on the allocation pattern.

Willy.
 
| The GC in CLR 2.0 can also occur on a timely basis irrespective of the
| threshold.
|

Not that I can see, start a managed application that doesn't allocate
objects while it keeps running, you will never see the GC kick in.

Willy.
 
| Here is a link to Rico Mariani PDC Session which mentions about the
| "Time-base criteria helps find idle cases"
|
http://microsoft.sitestream.com/PDC05/FUN/FUNL04_files/Botto_files/FUNL04_Mariani.ppt.
|
| So the GC has been changed to occur on a timely basis.
|

No this doesn't mean it's running on a timely basis, it means that the GC
not necessarely kicks off at the point the threshold is reached, it may be
delayed until idle time after the threshold has been reached. This is done
for performance reasons (a GC run stops all managed threads), now the GC
might get suspended until the CLR memory allocator is idling. The net result
however is that the size of the GC can get really large when you are
constantly allocating/deallocating small objects.

Willy.
 
Hi willy,

You have mentioned "..The net result
however is that the size of the GC can get really large ..". I didnt quite get the meaning of saying "size of GC". Did you mention about the heap. Also I would like to know, while a .net application is running, will the heap ever be full at any point of time due to garbage collection running in the background. can you point me to any good URl giving more detail about how and whys of heap management in .net context.

Thanks for your answers :)
pradeep_tp
 
Sorry, ...size of the GC heap can get ....

What I mean is that the Gen0 threshold is something like 256Kb - 500Kb, But
due to this enhancement, it's possible that Gen0 grows above this threshold
and that it reaches values like 2MB before the GC kicks in.
Note that the GC never runs in the background, it runs on a user thread
while all other managed threads in the application are suspended.
Check Maoni's Blogs at http://blogs.msdn.com/maoni/default.aspx for more
info about this subjects.

Willy.



| Hi willy,
|
| You have mentioned "..The net result
| > however is that the size of the GC can get really large ..". I didnt
quite get the meaning of saying "size of GC". Did you mention about the
heap. Also I would like to know, while a .net application is running, will
the heap ever be full at any point of time due to garbage collection running
in the background. can you point me to any good URl giving more detail about
how and whys of heap management in .net context.
|
| Thanks for your answers :)
| pradeep_tp
|
| "Willy Denoyette [MVP]" wrote:
|
| >
| > | > | Here is a link to Rico Mariani PDC Session which mentions about the
| > | "Time-base criteria helps find idle cases"
| > |
| >
http://microsoft.sitestream.com/PDC05/FUN/FUNL04_files/Botto_files/FUNL04_Mariani.ppt.
| > |
| > | So the GC has been changed to occur on a timely basis.
| > |
| >
| > No this doesn't mean it's running on a timely basis, it means that the
GC
| > not necessarely kicks off at the point the threshold is reached, it may
be
| > delayed until idle time after the threshold has been reached. This is
done
| > for performance reasons (a GC run stops all managed threads), now the GC
| > might get suspended until the CLR memory allocator is idling. The net
result
| > however is that the size of the GC can get really large when you are
| > constantly allocating/deallocating small objects.
| >
| > Willy.
| >
| >
| >
| >
| >
 
Back
Top