Asp. Processing scheme of OutOfMemoryException exception in net

Source: Internet
Author: User
Tags garbage collection memory usage thread

People who believe that doing large web applications in ASP.net have encountered outofmemoryexception this anomaly, I have studied this issue for a long time and have learned the reason for this problem in Microsoft's technical documentation and, to tell you the truth, I still don't have the perfect solution, and here's just some of the experience I've been working on. Come out and share with everyone, as much as possible to avoid this problem.

1) First, in the configuration of the hardware, the cause of this problem I think a lot of people already know, that is, there are some restrictions on the management of Memory IIS, the general understanding is that the 800M thread memory usage limit (through some of my customer practice proved to be so, or even lower ...), Whether w3wp or aspnet_wp, this restriction is obvious to the ASP.net application server machine configuration, more than 2G of memory for a simple Web server is very small, so the configuration of the Web server in the number of CPUs to consider more.

2 The scenario on the IIS configuration, IIS5.0 can install a iis5recycle program that uses the form of a service to recycle worker processes, installation instructions: http://support.microsoft.com/?id= 322350, for IIS6.0 can set the automatic recycle worker thread time on the application pool configuration, I will generally set at 2 o'clock in the morning:

3 on the configuration of the. NET Framework, modify the configuration section <processModel> property "MemoryLimit" in the Machine.config configuration file, which defaults to "60" and is a percentage data. We need to set this value according to the actual amount of memory on the server and then the upper limit of 800M, so IIS automatically reclaims the process when this threshold is reached

4 in the development of Web applications, must be as much as possible to reduce the use of memory waste, timely release of resources, I would like to say that there are 3 points: 1, through the code to actively call the Dispose method for resource release, 2, for the entity classes as much as possible reuse, do not make redundant declarations and create, 3, Reduce the use of Session, shorten the duration of the session, especially for large data objects as far as possible not stored in the session

5 A more general approach is to proactively capture outofmemoryexception exceptions in the base class of the Web application by try{}catch{}, and then call Gc.collect () to force garbage collection directly after discovering the exception.

Finally, a lot of friends mentioned that the 32-bit system for large memory use can open 3G mode, which itself is not a problem, but based on personal experience, it is not helpful for simple Web applications, if the Web server has more uses of course it is recommended to use this model.

I hope it will help you to deal with this problem.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.