ASP.NET memory management

R

Rob Nicholson

We're developing our first large scale ASP.NET web application and I'm a
little concerned over memory usage of aspnet_wp.exe on the development
server during testing. The application appears to use a lot of memory and
I've got the feeling that it's not all been released.

Some initial questions:

When a session times out, is ASP.NET/CLR supposed to release every resource
allocated during the session?

Is there anyway to display what's happening on a IIS server when it's
running an application? A log of some kind. Just memory per session would be
a start.

Are there any configuration options around memory management of ASP.NET on
IIS?

Despite what I've heard, do you actually have to carry out manual disposal
and memory collection. I've come from the VB6 world where the classic
circular reference (Obj1 points to Obj2 and Obj2 points to Obj1) causes both
objects (and their children) to stay in memory even though Obj1 and Obj2 are
both cleared to nothing. I currently believe the dream that CLR garbage
collection does work. I hope I can carry on with this dream... Waking up
into reality and having to implement cleanup code throughout the application
is more of a nightmare than a dream.

Cheers, Rob.
 
S

Scott Allen

HI Rob, see inline:

We're developing our first large scale ASP.NET web application and I'm a
little concerned over memory usage of aspnet_wp.exe on the development
server during testing. The application appears to use a lot of memory and
I've got the feeling that it's not all been released.

Some initial questions:

When a session times out, is ASP.NET/CLR supposed to release every resource
allocated during the session?

Memory resources will be taken care of by the garbage collector -
eventually. Chances are it will not happen at the exact moment a
session times out. Server processes in general tend to not give up
memory easily, chances are they will need it again in the future.
Chances are you may not have a problem, the best way to find out would
be to do some simulated stress testing. Saying a process uses "a lot"
of memory is too relative.
Is there anyway to display what's happening on a IIS server when it's
running an application? A log of some kind. Just memory per session would be
a start.

You could start with perfmon, which comes with the operating system.
Under the .NET CLR Memory counter category pay particular attention to
the Large Object Heap size and Gen 2 heap size. These areas contain
the large objects and the objects that are hanging around the longest.

There are also memory profilers you can use - CLRProfiler is free [1].
WinDbg [2] is the best tool for seeing exactly what you have on the
heap, but has a steep learning curve and too many details for most
memory scenarios. Still, the latest version has an extension command
(!dac for DumpAspnetCache) that can show you exactly what is in the
cache (ASP.NET keeps Sessions in the Cache collection internally).
Are there any configuration options around memory management of ASP.NET on
IIS?

You can set q peak amount of memory for the worker process to use,
once it hits this number the application recycles, which might not be
what you want. In IIS 6.0 this is set on the Application Pool
properties dialog.
Despite what I've heard, do you actually have to carry out manual disposal
and memory collection. I've come from the VB6 world where the classic
circular reference (Obj1 points to Obj2 and Obj2 points to Obj1) causes both
objects (and their children) to stay in memory even though Obj1 and Obj2 are
both cleared to nothing. I currently believe the dream that CLR garbage
collection does work. I hope I can carry on with this dream... Waking up
into reality and having to implement cleanup code throughout the application
is more of a nightmare than a dream.

Circular references are definitely not a problem in .NET.


[1]
http://www.microsoft.com/downloads/...52-D7F4-4AEB-9B7A-94635BEEBDDA&displaylang=en

[2] http://www.microsoft.com/whdc/devtools/debugging/default.mspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top