不使用所有内存/限制时的内存不足异常 [英] Out of memory exception when not using all the memory/limits

查看:283
本文介绍了不使用所有内存/限制时的内存不足异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们这里有一个问题,我们可以提供一些OutOfMemoryException.

We have an issue here where we can have some OutOfMemoryException.

我们将检查如何减少内存使用量,但我的问题是为什么现在得到它.

We will check how we can reduce the memory usage, but my question is why I get it at this point.

根据内存分析器和Windows任务管理器,该应用程序的权重仅为 400MB.

According to the Memory profiler, and the windows task manager, the application weights only 400MB.

对于我的理解(在此处确认),对于32位应用程序,限制应在2GB左右.我的计算机有16GB的内存,并且有很多可用的内存(超过4GB).

For what I understood(confirmed here), for 32bits applications, the limitation should be around 2GB. My computer has 16GB of ram, and there is plenty of ram available(more than 4GB).

那为什么现在我会收到此错误?

So why do I get this error now?

我的问题不是关于为什么我的应用程序的内存增加,而是更多地了解为什么它现在已经在发生. 我觉得这个限制不是固定的,但是我找不到任何参考.

My question is not about why my application has its memory growing, but more to understand why it's already happening now. I've the feeling that this limit is not a fixed one, but I can't find any reference on this.

调用堆栈(如果有帮助的话):

The call stack if it helps:

System.OutOfMemoryException: Out of memory.
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
   at Nevron.GraphicsCore.NBitmapGdiRenderSurface.Paint(Object sender, PaintEventArgs e, l1ll11Il1 contentPainter)
   at Nevron.Chart.WinForm.NControlView.Paint(Object sender, PaintEventArgs e)
   at Nevron.Chart.WinForm.NChartControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

修改 我有一个完全不同的堆栈跟踪的相同异常:

Edit I got the same exception with a totally different stack trace:

System.ComponentModel.Win32Exception (0x80004005): Not enough storage is available to process this command
   at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)
   at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
   at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
   at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
   at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.Allocate(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
   at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.Allocate(Graphics targetGraphics, Rectangle targetRectangle)
   at DevExpress.XtraBars.Docking2010.Views.BaseViewPainter.Draw(GraphicsCache cache, Rectangle clip)
   at DevExpress.XtraBars.Docking2010.Views.BaseView.Draw(GraphicsCache cache, Rectangle clip)
   at DevExpress.XtraBars.Docking2010.DocumentManager.PaintCore(Graphics g, Rectangle bounds)
   at DevExpress.XtraBars.Docking2010.DocumentManager.DevExpress.XtraBars.Docking2010.IDocumentsHostOwner.Paint(Graphics g)
   at DevExpress.XtraBars.Docking2010.DocumentsHost.OnPaint(Graphics g)
   at DevExpress.XtraBars.Docking2010.DocumentsHost.DoPaint(Message& m)
   at DevExpress.XtraBars.Docking2010.DocumentsHost.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

推荐答案

一种可能性是您的大对象堆已变得碎片化. IE.它有足够的空间,但没有足够大的空间来满足大对象的分配.

One possibility is that your large object heap has become fragmented. I.e. it has plenty of space but no space large enough to satisfy an allocation of a large object.

尽管似乎可以通过一种方法立即取消压缩.

The LOH is not usually compacted although there seem to be a way to do a one off compaction now.

如果确实存在问题,那么避免LOH碎片的一种方法是使用大型对象池,这些对象在完成处理后才返回池中,而不是让GC处理它们.

If that is indeed the issue, one way to avoid LOH fragmentation is through the use of pools of large objects that just get returned to the pool when you are done with them rather than letting the GC deal with them.

这篇关于不使用所有内存/限制时的内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆