博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.NET Out Of Memory Exception - Used 1.3GB but have 16GB installed
阅读量:5779 次
发布时间:2019-06-18

本文共 2541 字,大约阅读时间需要 8 分钟。

I am getting an Out Of Memory exception in my c# application when the memory usage for the application goes over about 1.3GB.

I had this same problem on a 32-bit machine with 3gb of memory and it made sense back then, but now I upgraded the hardware to a 64-bit machine with 16GB memory with the high - end motherboard and RAM but the Out Of Memory exception still occurs after 1.3GB!

I know that there are no single objects over 2GB and 1.3 is less the 2GB anyway, so the in-built MS 2GB limit on a single object is not likely to be the problem...

It seems like there is a windows kill-switch of some sort when an app reaches a certain memory usage threshold... Then there should be a way to configure this is in the registry perhaps?

Any help will be greatly appreciated!

Solution1:

There is no difference until you compile to same target architecture. I suppose you are compiling for 32 bit architecture in both cases.

It's worth mentioning that OutOfMemoryException can also be raised if you get 2GB of memory allocated by a single collection in CLR (say List<T>) on both architectures 32 and 64 bit.

To be able to benefit from memory goodness on 64 bit architecture, you have to compile your code targeting 64 bit architecture. After that, naturally, your binary will run only on 64 bit, but will benefit from possibility having more space available in RAM.

Solution2:

As already mentioned, compiling the app in x64 gives you far more available memory.

But in the case one must build an app in x86, there is a way to raise the memory limit from 1,2GB to 4GB (which is the actual limit for 32 bit processes):

In the VC/bin folder of the Visual Studio installation directory, there must be an editbin.exe file. So in my default installation I find it under

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\editbin.exe

In order to make the program work, maybe you must execute vcvars32.bat in the same directory first. Then a

editbin /LARGEADDRESSAWARE <your compiled exe file>

is enough to let your program use 4GB RAM. <your compiled exe file> is the exe, which VS generated while compiling your project.

If you want to automate this behavior every time you compile your project, use the following Post-Build event for the executed project:

if exist "$(DevEnvDir)..\tools\vsvars32.bat" (   call "$(DevEnvDir)..\tools\vsvars32.bat"   editbin /largeaddressaware "$(TargetPath)")

Sidenote: The same can be done with the devenv.exe to let Visual Studio also use 4GB RAM instead of 1.2GB (but first backup the old devenv.exe).

from:

转载地址:http://hlkyx.baihongyu.com/

你可能感兴趣的文章
2014暑假集训组队赛01
查看>>
基于jQuery带标题的图片3D切换焦点图
查看>>
杂题_POJ上的过桥问题
查看>>
C#AutoResetEvent和ManualResetEvent的区别
查看>>
[转]A plain english introduction to cap theorem
查看>>
C++11中的Lambda表达式
查看>>
从源代码上分析ListView的addHeaderView和setAdapter的调用顺序
查看>>
带节假日JS万年历控件代码
查看>>
美国地名大全(美国城市名称英文、中文)
查看>>
怎样在Linux下通过ldapsearch查询活动文件夹的内容
查看>>
常用的排序算法的时间复杂度和空间复杂度
查看>>
Samsung_tiny4412(驱动笔记09)----alloc_pages,kmalloc,vmalloc,kmem_cache,class
查看>>
PAT 1006. Sign In and Sign Out
查看>>
各大招聘网站信息实时查询浏览
查看>>
一次正确选择,改变一生命运!
查看>>
Java的内存泄漏
查看>>
c++ 队列
查看>>
PHP 设计模式 笔记与总结(8)策略模式
查看>>
.NET中使用Memcached的相关资源整理
查看>>
nyoj 1129 Salvation
查看>>