Detecting memory leaks in ASP.Net with IIS

This tutorial describes how to detect memory leaks in ASP.Net applications tested on IIS.

Related tutorials:

Detecting memory leaks in a service.
Detecting memory leaks in an application that is a child process of a service.
Detecting memory leaks in an IIS ISAPI DLL.
Detecting memory leaks in ASP.Net with Web Development Server.
Detecting detect memory leaks for a child process.

Example Web Application

An example web application to use with this tutorial is in <Memory Validator install directory>\examples\aspnetExample\aspnetExample\.

Load \examples\aspnetExample\aspnetExample\aspnetExample.csproj and build the configurations or build aspnetExample.csproj as part of the examples.sln solution.

Deploying the example web application for testing

Once you have built the example application, copy the contents of <Memory Validator install directory>\examples\aspnetExample\aspnetExample\ to the web root (for example c:\inetpub\wwwroot).

The resulting web root will look similar to this:

Memory Validator IIS ASP.Net webroot

Detecting memory leaks in the ASP.Net on IIS

  1. Choose the Launch > Services > Monitor IIS and ASP.Net… option.

    Memory Validator launch menu IIS and ASP.Net

  2. The Monitor IIS and ASP.Net dialog is displayed.

    Memory Validator IIS and ASP.Net dialog

    1. Choose the appropriate native/mixed-mode/.Net option to specify which types of code you want to detect memory leaks for. Mixed-mode is the default, as this collects memory allocation information for all types of code.
    2. Choose which ASP.Net worker process you are going to monitor. If you’re not sure just choose Any IIS.
    3. Specify the path to the IIS web root. 
    4. Select a web browser of your choice. For this example we’ll choose chrome.exe.
    5. Specify the URL that is going to be loaded from the web application. The default is http://localhost:80/Default.aspx
  3. When you click OK, Memory Validator will set up everything needed to interact with the IIS, the web browser will be started to load the specified URL.
  4. Memory Validator will instrument your ASP.Net application and start collecting memory allocation data.
    The first time you start IIS you may find that the web browser fails to open the web page because it takes longer to serve the page due to the memory allocation monitoring. If this happens just wait a few seconds then reload the page in the web browser.

Stopping IIS

When you have finished testing your ASP.Net application you need to stop IIS so that all .Net operations can conclude. 

If you had selected Stop IIS when web browser is closed on the Monitor IIS and ASP.Net dialog then you have nothing to do.

Otherwise, choose Launch > Services > Stop IIS

Memory Validator launch menu Stop IIS

IIS will be requested to stop. This may take 30 seconds or more.

When IIS stops, Memory Validator will finish monitoring memory allocations and prepare it’s final memory leak reports.

I’m not getting any memory allocation data. What can I do?

There are a few things to check.

  1. Check the diagnostics tab. If the NT Service API is working correctly, Memory Validator will have some data. Information on instrumentation failures will be on the diagnostic tab.
  2. Check the debug information dialog. You can access this from the Tools > DLL Debug Information… menu. This dialog will tell you which DLLs have debug information and which do not. Any DLLs that don’t have debug information you’ll need to ensure that debug information is built for these DLLs and is findable.


You have learned how to use Memory Validator to monitor ASP.Net applications using the IIS, and what to look at to diagnose errors if things don’t work first time.



Fully functional, free for 30 days