处理Exception of type System.OutOfMemoryException was thrown
来源:互联网 发布:浙江大学网络教育证书 编辑:程序博客网 时间:2024/05/21 09:24
在ASP.NET Web服务器上,ASP.NET所能够用到的内存,通常不会等同于所有的内存数量。
在machine.config配置文件中, 配置节<processModel>中有一个属性“memoryLimit”,这个属性的值是一个百分值,默认为“60”,即指定了ASP.NET进程(在任务管理器中大家就可以看到ASP.NET的进程,IIS5中为aspnet_wp,IIS6中为w3wp)能够使用所有物理内存的60%。当ASP.NET使用的内存量超过这个限额时,IIS会开始自动回收(recycle)进程,即创建一个新的进程去负责应付Http请求,而将旧进程所占用的内存回收。
当我们有一台很大内存的服务器时,“memoryLimit”这个值是需要进行适当的调整的。比如我们准备了一台chemas-microsoft-comofficemarttags" />t="on">4G内存的服务器,那么t="on">4G×60%=t="on">2.4G。但是,对于Win32操作系统,一个进程所能占用的所有内存空间只有t="on">2G。当ASP.NET进程占用的内存开始达到t="on">2G时,由于它并没有达到t="on">2.4G的“回收阈值”,所以IIS不会启动recycle进程操作,但是由于Win32的限制,实际上已经不能给这个进程分配更多的内存了,于是,OutOfMemoryException就很可能会被抛出了。为了避免这样的情况,我们就必须将“memoryLimit”适当调小,以让IIS更早的进行进程回收。
微软推荐的ASP.NET进程占用内存是不超过60%,并最好使计算出的实际值不超过t="on">800M。就是说,对于一台t="on">4G内存的服务器,最好将“memoryLimit”属性设置成“20”。设置一个适当的回收阈值,让IIS适时的进行进程回收,对于保证整个服务器的稳定运行,避免OutOfMemoryException是非常重要的。
在IIS6中,ASP.NET进程的回收阈值不再由 配置节中的“memoryLimit”属性决定,而是由IIS管理器中的应用程序池配置中的设置决定。
但是,即使正确设置了这些配置,也不能保证完全避免OutOfMemoryException的发生,原因可能是多样而复杂的,比如内存回收操作可能耗时太多等等。开发人员要注意的,就是在代码中时刻牢记不要无谓的使用和浪费内存。:)
如果你有一台大内存的服务器,同时对Win32操作系统中对于进程最高使用t="on">2G内存的限制很郁闷,可选的解决方法有两个:
1、使用/3GB模式启动计算机,方法参加文后的链接
2、使用Windows Server 2003 64bits Edition
- 处理Exception of type System.OutOfMemoryException was thrown
- Exception of type System.OutOfMemoryException was thrown.
- Exception of type 'System.OutOfMemoryException' was thrown
- c#中 Exception of type 'System.OutOfMemoryException' was throw的解决办法
- c#中 Exception of type 'System.OutOfMemoryException' was throw的解决办法
- System.OutOfMemoryException处理
- java-No exception of type ConfigurationException can be thrown; an exception type must be a subclass
- An unhandled exception of type 'System.StackOverflowException'
- No exception of type JmsException can be thrown; an exception type must be a subclass of Throwable
- No exception of type HibernateException can be thrown; an exception type must be a subclass of Thro
- No exception of type BeansException can be thrown; an exception type must be a sunclass of Throwable
- An unhandled exception of type "System.InvalidCastException" occurred
- System.OutOfMemoryException
- System.OutOfMemoryException
- System.OutOfMemoryException
- System.OutOfMemoryException
- System.OutOfMemoryException
- System.OutOfMemoryException
- 小知识:.Net中?和??的含义
- 7天连锁CEO郑南雁:以IT头脑经营酒店
- Essential Silverlight翻译连载---第四章 续3
- 详解ArcGIS Server安装与配置
- 敲门贴
- 处理Exception of type System.OutOfMemoryException was thrown
- photoshop调色见解
- 实现GridView控件的删除多条记录功能系列(3)
- 在SSH框架中使用Validator框架
- Essential Silverlight翻译连载---第五章 交互和事件处理
- 怎样选择瓷砖?
- Winamp时代的终结
- Essential Silverlight翻译连载---第五章 续1
- PowerDesigner 12.5 导致 Word 2003鼠标没反应的解决方法