ASP.NET 中关于 System.OutOfMemoryException 的问题与解决方法
来源:互联网 发布:手机淘宝如何改差评 编辑:程序博客网 时间:2024/05/20 09:10
ASP.NET 中关于 System.OutOfMemoryException 的问题与解决方法 收藏
之所以发生System.OutOfMemoryException这个问题,是因为多处理器(或多核心)计算机上的 .NET CLR 的 Garbage Collection (GC) 机制默认是使用 Server Mode (服务器模式) 在运行的,换句话说,就是「每一颗 CPU 都会有独立的 GC 内存空间(堆栈, Heap)」,所以如果你的 GC 内存空间 用掉了 500MB 且你有 4 颗 CPU 的话,就等于耗费了 2GB 的内存,进而发生 System.OutOfMemoryException 异常!
要解决这个问题的方式就是将 GC 设置为 Workstation Mode (工作站模式),这样就可以整台主机共享同一个 GC Heap,以节省内存的使用。要将预设的 GC 修改成 Workstation Mode 必须要修改 %WINDIR%/Microsoft.NET/Framework/v2.0.50727/Aspnet.config 配置文件 ( 如果是 .NET 1.1 要修改 %WINDIR%/Microsoft.NET/Framework/v1.1.4322/Aspnet.config 配置文件 ):
预设的 Aspnet.config 长这样:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="false" />
<legacyImpersonationPolicy enabled="true"/>
<alwaysFlowImpersonationPolicy enabled="false"/>
<SymbolReadingPolicy enabled="1" />
</runtime>
</configuration>
需加上一行 <gcServer enabled="false"/> 如下:
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<runtime>
<gcServer enabled="false" />
<legacyUnhandledExceptionPolicy enabled="false" />
<legacyImpersonationPolicy enabled="true"/>
<alwaysFlowImpersonationPolicy enabled="false"/>
<SymbolReadingPolicy enabled="1" />
</runtime>
</configuration>
这样就设置完成了!
不过像这种出现 Out of Memory 的异常在 64 位的操作系统中几乎不会出现问题,所以如果你是使用 64 位的操作系统(如:Windows Server 2003 64bit ) 的话,是不太需要做这样的调整的,但你的内存还是要够多才行,否则过多的分页状况还是会降低你 ASP.NET 应用程序的执行性能!
除了这点之外,在正式(Production)环境中的 ASP.NET 应用程序一定要在 web.config 中关闭开发时期设定的 debug 与 trace,才不会对内存造成额外的负担。因为 ASP.NET 应用程序在启用 debug mode 的时候所有的 Symbol 檔(*.pdb)都会被加载到内存中,不但会消耗不少内存,也会降低执行效能。详情请见微软知识库:Quick things to check when you experience high memory levels in ASP.NET
- ASP.NET 中关于 System.OutOfMemoryException 的问题与解决方法
- ASP.NET 中关于 System.OutOfMemoryException 的问题与解决方法
- 解决 ASP.NET 中 System.OutOfMemoryException 的问题
- 解決 ASP.NET 中 System.OutOfMemoryException 的問題
- 解決 ASP.NET 中 System.OutOfMemoryException 的問題
- 解决'System.OutOfMemoryException' 的问题
- .Net System.OutOfMemoryException
- ASP.NET中的OutOfMemoryException
- ASP.NET中的OutOfMemoryException
- .Net 内存溢出(System.OutOfMemoryException
- 引发类型为“System.OutOfMemoryException”的异常-.Net 内存溢出
- 关于asp.net中ajax的问题:AjaxControlToolkit 未定义的解决方法
- ASP.NET中System.Web.UI.Page的继承问题
- 关于Asp.net中Cookie的问题
- 关于Asp.net中Cookie的问题
- 关于asp.net网址出现乱码问题的解决方法
- System.OutOfMemoryException: 引发类型为“System.OutOfMemoryException”的异常
- OutOfMemoryException问题的处理
- 指令B和BL的区别
- dijit.Dialog样例及其原型关系
- 指令B和BL的区别
- 19.Mediator(行为型模式)
- 提高PHP编程效率的53个要点
- ASP.NET 中关于 System.OutOfMemoryException 的问题与解决方法
- jdk 1.5新特性--for 循环加强
- 求给出三个坐标点所围成的三角形的高
- 算法网址
- rawurlencode和urlencode函数比较
- JForum登录用例(普通用户)
- JavaSwing 开源社区门户
- delphi操作word
- 技巧:用 C 语言实现程序的多态性