.Net的Outofmemory异常及大内存使用

来源:互联网 发布:邪恶爱之知可知子伯母 编辑:程序博客网 时间:2024/05/21 10:51
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

        从去年起我们的服务器偶尔会抛出OutOfMemoryException,即没有足够的内存继续执行程序时引发的异常。服务器内存加到4G也仍会出现该问题。软件是UO的第三方模拟器。事实上,从任务管理器里,可以看到软件占用了约1G左右的内存,当然因为GC的缘故,实际软件使用的内存在600M左右。为避免超过1G多内存的占用,并抛出Outofmemory异常,设定在内存占用到一定值时进行强制GC,一下子可以减去几百兆,但终究是没彻底解决问题。        最近国外论坛贴了相关处理方法,在此转述一遍,希望对遇到类似问题的朋友有帮助。

对于2G内存的服务器,.Net只能使用1.2G内存。对于4G内存的服务器,.Net可使用2.4G内存。但系统需要进行如下设置:1、 在boot.ini文件中增加/3GB的开关。[boot loader]timeout=30default=multi(0)disk(0)rdisk(0)partition(2)WINNT[operating systems]multi(0)disk(0)rdisk(0)partition(2)WINNT="????" /3GB2、在命令行窗口,进入该目录,如 cd "C:Program FilesMicrosoft Visual Studio .Net 2003Vc7in"3、运行link命令: link -edit -LARGEADDRESSAWARE server.exe  (server.exe为你的.Net程序)4、你的server.exe就可以使用到2.4G内存了

.Net 1.2好像没解决这个问题,新的2.0还没空做测试,不知道2.0在内存管理和GC的性能上有无大的变化。

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击