Author: Chainet from: cnblogs
Introduction
The product I participated in was a relatively large ASP. NET system. If the system runs for a long time in the testing department and the customer, the system usually encounters an outofmemoryexception. There are many causes of memory overflow errors, mainly in the server configuration and code writing aspects can be optimized and improved, to avoid such problems, but completely put an end to it is more difficult. The following are some of my solutions.
Server Configuration
1. Install. NET Framework 1.1 Service Pack 1
Patch part solved some memory leakage problem, for: http://www.microsoft.com/downloads/details.aspx? Displaylang = en & familyid = a8f5654f-088e-40b2-bbdb-a83353618b38
2. Use more memory
A. Enable/3 GB switch (if you have more than 3 GB memory ). This configuration is only supported in Windows 2000 Advanced Server, data center, and Windows Server 2003 or later versions. See:
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnpag/html/scalenetchapt17.asp
Http://support.microsoft.com/default.aspx? SCID = KB; en-US; 820108
B. even if you have a lot of memory. net (not ASP. net working process,.. Net memory usage is limited. You can increase the configuration usage to reduce memory overflow. The method is as follows:
Modify machine. config File, usually in % System % \ Microsoft. in the net \ framework \ v1.1.4322 \ config directory, modify the memorylimit in the processmodel element, which is greater than the default value of 60 (which means 60% of the physical memory ).
3. Recycle working threads
Setting IIS to regularly clear work process is a good way to avoid this exception. However, this function is only supported by IIS 6.0 (that is, IIS on Windows 2003.
The configuration method is as follows:
Modify the application pool configuration of IIS, select defaappapppool (if your system uses this pool), right-click Properties-> reconfiguring setting, then, modify the "recycle worker processes at the following times: 'and other configurations as needed. It is better to regularly recycle the worker process to avoid the process being recycled, the client session is lost.
IIS 2000 is installed on Windows 5.0 server and does not support recycle. However, it is not difficult to implement this function. Iis5recycle provided by Microsoft for IIS is such a program. After it is installed, it provides the recycle working process as a service.
Installation instructions see http://support.microsoft.com /? Id = 322350
The image indicates the configuration information after installation! Is it exactly the same as that in IIS6?
Notes for coding
1. Usage problems of the system. Drawing Class
System. Drawing uses a lot of system resources and unmanaged code, so be careful when using it. Pay attention to memory leakage (Memory Leak) such as bitmap. maketransparent usage problems:
Http://www.dotnet247.com/247reference/msgs/40/202528.aspx
2. New byte [] Problem
A new large byte array is often used for stream processing. However, multiple users consume a large amount of memory. The correct method should be to define a small byte array as a cache and then use it cyclically. For example, in our program, when the image (or attachment) is too large or too large, the new byte [length] may consume too much memory.
3. Avoid using large object arrays or small object large arrays
Efficiency issues (including memory usage issues) must also be emphasized during programming ).
4. Pay attention to releasing objects when calling the COM interface.