Memory Usage and Garbage Collection

A

Andy

Along with many others I've noticed the large amount of memory that
can be taken up by the aspnet_wp.exe. I've found that I can better
control and limit this memory consumption by including a GC.Collect()
in the Application_EndRequest() event handler in the Global.asax file.

Whilst this appears to help my memory consumption issues I've also
read that forced GC.Collect() can be inefficient.

Assuming that I don't see any adverse effects on performance - which I
haven't yet, but early days in the testing - does anybody know of any
reasons why I shouldn't adopt this approach?

Thanks
Andy
 
K

Kevin Spencer

I think you should be asking if anybody knows of any reasons why you SHOULD
adopt this approach. The default is to let the Framework manage your memory
for you, and defaults are defaults for a reason. Unless it's causing a
problem, I would let the Framework do what is designed to do best.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
E

Eric Lawrence [MSFT]

Agreed.

That said, a deveoper should of course review the ASPX pages and try to
minimize the memory consumption; converting from strings to stringbuilders
where necessary, etc.

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Thanks a lot for Kevin and Eric's suggestions.

Hi Andy,

As Kevin and Eric have mentioned, generally the dotnet clr will
automatically control the memory management. The "System.GC.Collect" will
force the clr to execute collection, but System.GC.Collect() is used for
demonstration purposes, not as a recommended procedure. Explicitly calling
GC.Collect() changes the GC's autotuning capabilities. Repeatedly calling
GC.Collect() suspends all threads until the collection completes. This
could greatly impede performance. And here is the reference on "Forcing
Garbage Collection" in MSDN:

#Forcing a Garbage Collection
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconforcingcollection.
asp?frame=true

And you may also view the following reference in MSDN for more detailed
description on Garbage Collection in DOTNET:
#Programming for Garbage Collection
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconprogrammingessenti
alsforgarbagecollection.asp?frame=true

Further more, as you mentioned the performance in ASP.NET, below are some
tech articles discussing on it:

#ASP.NET Performance Monitoring, and When to Alert Administrators
http://msdn.microsoft.com/library/en-us/dnaspp/html/monitor_perf.asp?frame=t
rue

#Production Debugging for .NET Framework Applications
http://msdn.microsoft.com/library/en-us/dnbda/html/DBGch02.asp?frame=true

Hope these help.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
A

Andy

Hi Guys,

Thanks very much for the advice - I'll revert to letting the GC take
responsibility. Given that memory consumption on the aspnet_wp seems
so variable are there any articles or guidelines indicating what
represents normal operation and what might indicate a design or coding
problem?

My project makes extensive use of the 'Cache' for storing sections of
dynamic pages and I'm a little bit concerned about the scalability of
this approach, particularly with regards to memory consumption, but
I'm finding it difficult to get a clear indication of how memory
requirements of the Cache are varying.

Thanks,
Andy
 
S

Steven Cheng[MSFT]

Hi Andy,

Thanks for your response. I think the following tech articles may help you
on designing high-performance WEB application and how to properly control
memory management:

#Developing High-Performance ASP.NET Applications
http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondevelopinghigh-per
formanceaspnetapplications.asp?frame=true

#Am I Losing My Memory?
http://msdn.microsoft.com/library/en-us/dnaskdr/html/askgui09172002.asp?fram
e=true

#Performance Counters for ASP.NET
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconPerformanceCounter
sForASPNET.asp?frame=true

#ASP.NET Performance Monitoring, and When to Alert Administrators
http://msdn.microsoft.com/library/en-us/dnaspp/html/monitor_perf.asp?frame=t
rue

#Production Debugging for .NET Framework Applications
http://msdn.microsoft.com/library/en-us/dnbda/html/DBGch02.asp?frame=true

#ASP.NET Caching Features
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaspcachingfeatures
..asp?frame=true


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
A

Andy

Hi Steven,

Thanks for your reply - following your earlier response I worked
through the articles you directed me to and feel that I am now making
progress and starting to get a handle on how to memory management
works - and now I have plenty more reading to do!

Thanks again,
Andy
 

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,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top