Saturday, January 21, 2006

.net CLR garbage collection

While looking through our application on how to optimize it, I had several questions about the debugger, like: 1. When does the CLR decide to run the garbage collection (GC). 2. What is the size of the managed heap. How does it resize 3. What are the implications of GC on speed of the application. Found all my answers and more at these websites. The following 2 give an excellent introduction to the GC algorithm that .NET uses. (recommended read) http://msdn.microsoft.com/msdnmag/issues/1100/GCI/ http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetGCbasics.asp Did you know that in tests, the CLR was quicker in allocating memory then normal win32 allocations. Apparently, the reason is that one can always be assured that when the CLR is requested for memory consecuitevely the space will be contigous and hence could all be in the CPU's memory, whereas in Win32, the memory could be fragmented and all over the place. Under the normal course of events, the GC performs periodic collections after every 1MB of allocations, the heap is compacted if it gets too fragmented, and empty segments are returned to the operating system as long as the collector’s 1 MB cache is full (this is for the .NET compact framework) http://blogs.msdn.com/stevenpr/archive/2005/12/14/503818.aspx Another page that is very good (this is a white paper) http://www.gotdotnet.com/team/libraries/whitepapers/resourcemanagement/resourcemanagement.aspx The following pages(blogs) have lots of in depth info about the operations of the garbage collector in .NET Using GC Efficiently – Part 1 by Maoni http://blogs.msdn.com/maoni/archive/2004/06/15/156626.aspx Using GC Efficiently – Part 2 by Maoni http://blogs.msdn.com/maoni/archive/2004/09/25/234273.aspx Using GC Efficiently – Part 3 by Maoni http://blogs.msdn.com/maoni/archive/2004/12/19/327149.aspx Using GC Efficiently – Part 4 by Maoni http://blogs.msdn.com/maoni/archive/2005/05/06/415296.aspx Using performance counters http://blogs.msdn.com/maoni/archive/2004/06/03/148029.aspx Tools for debugging memory related problems http://blogs.msdn.com/maoni/archive/2004/11/08/254288.aspx Finalization and GC http://blogs.msdn.com/maoni/archive/2004/11/04/252697.aspx

No comments: