High memory usage with usercontrols in Internet Explorer - using Debug Diag

I was helping a colleague with an interesting case yesterday concerning a memory leak in IE when using winforms usercontrols. We got a nice little repro with a very basic user control that displayed a picture and each time the page was refreshed it appeared to leak quite a bit of memory,and inducing a garbage collection had no […]

I was helping a colleague with an interesting case yesterday concerning a memory leak in IE when using winforms usercontrols.

We got a nice little repro with a very basic user control that displayed a picture and each time the page was refreshed it appeared to leak quite a bit of memory,
and inducing a garbage collection had no effect on the memory.

I started off with setting it up on my machine, and then I used Debug Diag 1.1  to track down the leak... Debug diag is not all that great for managed/.net memory leaks since the GC manages the memory for you as I'll show later... but I figured that since I had a repro it was worth a try...

Some notes on how debug diag works: Debug diag is basically a debugging helper that allows you to take memory dumps of a process or set up different rules like crash rules, memory rules, exception rules and hang rules.  It also has a leaktracking feature which I will talk about in more detail in a bit.  It also has a number of scripts (and allows you to write your own scripts) for automated analysis.  Basically you load up a dump file in debug diag (can even be a dump file gathered with windbg) and choose the script you want (hang, crash or memory) and then Debug Diag will produce a report with stacks and information about what it thinks is the problem.

The downloads page has very nice information concerning how you use Debug Diag to troubleshoot different issues.

Debug diag and memory leaks:

This excerpt is copied straight from the downloads page:

To debug memory and handle usage, use one of the following:
1. Create a leak rule against the process in question. The leak monitoring feature will track memory allocations inside the process. Tracking is implemented by injecting a DLL (leaktrack.dll) into the specified process and monitoring memory allocations over time. When configuring a memory and handle leak rule, you can specify memory dump generation based on time or memory usage.
2. Using the “processes” view, right-click the process in question and select the “monitor for leaks” option. When the process has grown to the suspected problem size, manually dump the process by right-clicking on the same process in the processes view and choosing the “Create Full Userdump” option.

In esscence what this means is that any memory that has been allocated and not been de-allocated will be reported as a possible leak.  It is very important that you turn on leaktracking for a sufficient amount of time (or raise in memory usage) that you can weed out the real leaks for the stacks that allocated memory recently and just hasn't had the time to de-allocate it.

Another item worth mentioning is that by default debug diag will not track any stacks for the first 15 minutes (to avoid mixing in all the allocations made on startup which are not really leaks but just getting you up to baseline memory usage).

Full Article

Microsoft, IE, Internet Explorer, Memory, ASP.NET, Debugging, Debug, Troubleshooting