Article ID: 893660 - Last Review: May 18, 2007 - Revision: 3.7 Quick things to check when you experience high memory levels in ASP.NETASP.NET Support Voice columnThings to check when you you experience high memory levels in ASP.NETNoticeIn the April 2005 Support Voice column, we inadvertently provided a link to the wrong file. Instead of linking to a download for the Web service, we linked to the XML file that is returned by the Web service. That link has been corrected. If you'd like to review the article with the correct file attached, see the following article in the Microsoft Knowledge Base:893659
(http://support.microsoft.com/kb/893659/
)
Dynamic page updates using XMLHTTP
To customize this column to your needs, we want to invite you to submit your ideas about topics that interest you and issues that you want to see addressed in future Knowledge Base articles and Support Voice columns. You can submit your ideas and feedback using the Ask For It
(http://support.microsoft.com/common/survey.aspx?scid=sw;en;1176&p0=&p1=&p2=&p3=&p4=)
form. There's also a link to the form at the bottom of this column. On This PageINTRODUCTION Hello, this is Michael Graham from the ASP.NET team, and
this will be my first of hopefully many entries to this column. Just a quick
note about myself: I started with the ASP team in 1997 and was there not long
after the introduction of Visual InterDev 1.0, Microsoft's first foray into the
world of server-side applications in the Internet environment. So I have been
at this for quite a long time! Today, I'm going to go over some reasonably
simple things that you can check for when you find yourself running into memory
issues in ASP.NET. We'll start with some common issues, actions you can take to
remedy these issues, and a brief explanation of why these situations can cause
problems. Let's get to it! What is considered high memory?Obviously, this is going to be dependent on volume and activity of specific applications. But, in general, high memory is when see that your Aspnet_wp.exe process (Internet Information Services (IIS) 5.0) or W3wp process (IIS 6.0) memory is consistently increasing and is not returning to a comfortable level. In very general terms, a comfortable level would be under 600 MB in the default 2 GB user memory address space. Once the memory level is higher than that, we are performing less than we should be, and this may affect other applications running on the system. The key here is to understand that some applications require more memory than others, and if you are exceeding these limits, you may want to add more memory or add another server to your Web farm (or consider a Web farm). Also, profiling is recommended in these cases, which can enable developers to create leaner applications. In this article, we are looking at a situation where you consistently see memory rise until the server stops performing.Common reasons for high memoryApplication set up for debuggingOne reason for high memory that we see here in Support a lot is when you have debugging, tracing, or both enabled for your application. While you are developing your application, this is a necessity. By default, when you create your application in Visual Studio .NET, you will see the following attribute set in your Web.config file:If you get nothing else from this article, I do hope you get this. Leaving debugging enabled is bad. We see this all too often, and it is so easy to change. Also, remember that this can be set at the page level, so make sure that all of your pages are not setting this. String concatenationThere are applications that build HTML output by using server-side code and by just building one big HTML string to send to the browser. This is fine, but if you are building the string by using "+" and "&" concatenation, you may not be aware of how many large strings you are building. For example:306821
(http://support.microsoft.com/kb/306821/
)
How to improve string concatenation performance in Visual Basic .NET
306822
(http://support.microsoft.com/kb/306822/
)
How to improve string concatenation performance in Visual C# .NET
.NET Framework 1.1 Service Pack 1 (SP1)If you are not running the .NET Framework 1.1 SP1 yet, install this if you are experiencing memory issues. I won't go into great detail, but basically, with SP1 we are now allocating memory in a much more efficient manner. Basically, we are allocating 16 MB at a time for large objects rather than 64 MB at a time. We've all moved, and we all know that we can pack a lot more into a car or truck if we are using a lot of small boxes rather than a few large boxes. That is the idea here.Don't be afraid to recycle periodicallyIn IIS 6.0, by default, we recycle application pools every 29 hours. In IIS 5.0, the Aspnet_wp.exe process will keep going until you end the task, restart IIS, or restart the computer. This means that this process could be running for months. For some applications, it's a pretty good idea to just restart the worker process every couple of days or so, at a convenient time.Questions to askThe previous were all things that you can "fix" quickly. However, if you are experiencing memory issues, ask yourself these questions:
DebuggingI won't get into setting up WinDbg. But here are some commands you can use to see what exactly is in your memory, if you wish to troubleshoot more complicated issues.Once you have found an object taking a lot of memory, you can dig further by using the following command: To learn more about how to set up and use these commands, take a look at this previous Support Voice column: 892277
(http://support.microsoft.com/kb/892277/
)
Troubleshooting ASP.NET using WinDbg and the SOS extension
We'll be trying to incorporate more ways to use this
wonderful diagnostic tool for specific situations in these columns. Please let
us know if we are doing a good job with this!ResourcesMemory articlesGarbage Collector Basics and Performance
Hints http://msdn2.microsoft.com/en-us/library/ms973837.aspx (http://msdn2.microsoft.com/en-us/library/ms973837.aspx) Garbage Collection: Automatic Memory Management in the Microsoft .NET Framework http://msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx (http://msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx) Garbage Collection-Part 2: Automatic Memory Management in the Microsoft .NET Framework http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx (http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx) Debugging Memory Problems http://msdn2.microsoft.com/en-us/library/ms954591.aspx (http://msdn2.microsoft.com/en-us/library/ms954591.aspx) Performance articlesDeveloping High-Performance
ASP.NET Applications As always, feel free to submit ideas on topics you want addressed in future columns or in the Knowledge Base using the Ask For It
(http://support.microsoft.com/common/survey.aspx?scid=sw;en;1176&p0=&p1=&p2=&p3=&p4=)
form.http://msdn2.microsoft.com/en-us/library/5dws599a(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/5dws599a(vs.71).aspx) ASP.NET Performance Monitoring, and When to Alert Administrators http://msdn2.microsoft.com/en-us/library/ms972959.aspx (http://msdn2.microsoft.com/en-us/library/ms972959.aspx) Improving .NET Application Performance and Scalability http://msdn2.microsoft.com/en-us/library/ms998530.aspx (http://msdn2.microsoft.com/en-us/library/ms998530.aspx) 10 Tips for Writing High-Performance Web Applications http://msdn.microsoft.com/msdnmag/issues/05/01/ASPNETPerformance/default.aspx (http://msdn.microsoft.com/msdnmag/issues/05/01/ASPNETPerformance/default.aspx) Rediscover the Lost Art of Memory Optimization in Your Managed Code http://msdn.microsoft.com/msdnmag/issues/05/01/MemoryOptimization/default.aspx (http://msdn.microsoft.com/msdnmag/issues/05/01/MemoryOptimization/default.aspx)
| Article Translations
|
Back to the top
