Believe in ASP. net medium and large Web applications have encountered the outofmemoryexception exception. I have been studying this problem for a long time. I also learned the cause of this problem in Microsoft's technical documentation. To be honest, at present, I still have no perfect solution. Here I will share some of my experiences in solving this problem with you to avoid this problem as much as possible.
1) First of all, in terms of hardware configuration, I think many people already know the cause of this problem, that is, IIS has some restrictions on memory management, it is widely recognized that the thread memory usage limit is MB (some of my client practices prove this is true, or even lower ...), whether it is w3wp or aspnet_wp, this restriction applies to ASP. NET application server machine configuration, its significance is very obvious, more than 2 GB of memory for a simple web server is very small, therefore, the number of CPUs can be considered in the web server configuration.
2) For IIS configuration, iis5.0 can install an iis5recycleProgram, The program uses the form of service to recycle the working process, installation instructions: http://support.microsoft.com /? Id = 322350. For iis6.0, you can set the time for auto-collect worker threads in the application pool configuration. Generally, the time is set at a.m :)
3) In.. NET Framework configuration, modify the machine. in the configuration section <processmodel> Of the config configuration file, the attribute "memorylimit" is set. The default value of this attribute is "60", which is a percentage data. We need to calculate the actual memory size of the server, then, this value is set based on the maximum mb. When this threshold is reached, IIS will automatically recycle the process.
4) in the development of Web applications, We must minimize the waste of memory usage and release resources in a timely manner.CodeActively call the dispose method to release resources. 2. Reuse entity classes as much as possible without additional comments and creations. 3. Reduce session usage and shorten the session validity period, do not store big data objects in sessions as much as possible.
5) a common method is to actively catch the outofmemoryexception in the basic class of the Web application through try {} catch {}. If this exception is found, GC is called directly. collect () for forced garbage collection.
Finally, many of my friends mentioned that the 32-bit system can enable the 3G mode for large memory usage. There is no problem in itself, but according to my personal experience, it is not helpful for pure web applications, if the Web server has more functions, we also recommend this mode.
We hope to help you solve this problem.