Observe an example of garbage collection, just to learn more about it and get some insight into the general platform. We may not have a specific bug to fix here, but we want an idea of how it works over time. We want to see a real-world visualization of garbage collection. Also we want to look at some other tools we can observe garbage with.
There are several tools I want to introduce here. First, I will show my custom application called Memory Watcher, which continually polls Windows for information about a process's working set. Then I will touch on CLRProfier and Process Monitor, both provided by Microsoft.
My .NET program "Memory Watcher" can observe collections over time, as well. It can also give you an idea of the proportions of the collections. Collections that are very frequent or big could be seen in this chart. The following chart shows the memory usage of a program that runs in the background frequently and regularly.
The sawtooth line shows peaks where the garbage collection is triggered, and then dips where it has already run and the memory is lower. We can see that this program doesn't consume too much memory over time. For more about this, see my article about Memory Watcher and how I used it on web browsers.
You should definitely have CLRProfiler on your system, as it is not only free but very useful. It can help you visualize memory usage of a process. (Note that this only works for .NET processes, so would not work for web browsers, for example.) Here is how to get started with this tool, and then what you might see.
The colorful lines (representing memory) keep building up, until they are flushed away and then the process starts again. The peaks are right before the garbage collections, and the dips are right after the collections. This is a good way to visualize the collections in .NET apps.
Open Process Explorer (procexp.exe) as administrator, and you should see columns called "Methods Jitted" and "Gen 0 Collections". When a method is compiled in your .NET program, the "Methods Jitted" column cell will increase. This can give you a rough idea of how big and complex your .NET app is. For more information about memory in Process Explorer, follow these steps.
These tools can help you keep track of memory usage and understand how garbage collection works in your application better. We can use tools like those provided by Microsoft, or custom tools. Garbage collection is powerful and efficient, but it needs to be kept in check in case our algorithms have a major inefficiency.