Monitor .NET application performance with the CLR Profiler
Tuesday, April 17, 2007 09:14 AM
When you notice memory issues cropping up in your .NET applications, turn to the freely available CLR Profiler. It allows you to take a peek under the hood of .NET applications and monitor the garbage collector heap.
In the .NET Framework, memory management is supposed to be handled automatically by the system. This allows you to concentrate on the important issues of application design and development. Unfortunately, this utopia has not been completely realized as memory issues still appear in .NET-based applications. This article examines one tool--the CLR (Common Language Runtime) Profile--that you may use to track down memory issues.
Garbage collection
The .NET platform adopted the garbage collection approach used in Java. That is, the .NET system tracks all
memory blocks allocated in an application. It knows when memory is allocated
and what monitors it uses. The system also knows when it is no longer used and frees it up. The
garbage collector handles these tasks, but it does not totally divorce you from
understanding memory allocation.
Objects in .NET are allocated from an area of memory called the managed heap. The heap is described as managed because, after you ask it for memory, the garbage collector takes care of its cleanup.
Garbage collection begins by assuming all objects are unnecessary until proven otherwise. An object proves that it is necessary essentially by its references, or who it is referenced by. If the object is necessary, it is not part of the garbage collection cycle. On the other hand, if the object is not necessary, the object is flagged to be discarded.
While garbage collection is an automatic process, you should still be aware of how memory is utilized in an application. This allows you to decide if the application is properly using its memory and how the garbage collector is being utilized. This involves knowing the life of objects used to determine how often garbage collection is called in order for you to determine if the garbage collector is taxed.
Code profilers can help with this process by providing a peek at the inner workings of an application, allowing you to gain a better understanding of memory usage. The .NET CLR includes a profiling API that you may use to write custom profilers for managed applications. There are plenty of commercial profiler tools available, but Microsoft provides a free one called the CLR Profiler.


» Blades for simpler IT management







There are currently no comments for this post.