我们这里有一个问题,我们可以有一些OutOfMemoryException。
我们将检查如何减少内存的使用,但我的问题是为什么在这个时候获得,。
根据内存分析器和windows任务管理器,应用程序的重量仅为400 to。
对于我所理解的(在此确认),对于32位应用程序,限制应该在2GB左右。我的电脑有16 4GB的内存,还有很多可用的内存(超过4GB)。
那么,为什么我现在要得到这个错误呢?
我的问题不是为什么我的应用程序的内存增长,而是更多地了解为什么它现在已经发生了。我觉得这个限制不是固定的,但我找不到任何参考。
如果调用堆栈有帮助,则调用堆栈:
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)编辑I得到了完全不同的堆栈跟踪的相同异常:
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)发布于 2015-10-14 10:36:57
一种可能是,您的大型对象堆已变得支离破碎。也就是说,它有足够的空间,但没有足够大的空间来满足一个大对象的分配。
虽然似乎有一种方法来做现在一次关闭压实,但LOH通常并不是很紧凑的。
如果这确实是问题所在,避免LOH碎片的一种方法是使用大型对象池,这些对象在处理完这些对象时只返回到池中,而不是让GC处理它们。
发布于 2015-10-14 10:35:45
您可能会看到内存碎片的结果。例如,当您拥有2GB的空闲内存,但是您最大的内存块比200 2GB要小得多时,就会发生这种情况。然后尝试分配一个400 of的块并获得内存不足的异常。
而且,如果您正在使用GDI+,它有一个在各种情况下抛出内存异常的坏习惯,其中大部分与内存无关。
在查看了您的跟踪之后,可以很容易地看到我提到的GDI+的某些特性。在过去,我在文件权限中遇到过这种情况,比如加载位图时。如果我是你我会检查的。不是专门的文件权限,而是已知GDI+会产生OOM异常的情况。
https://stackoverflow.com/questions/33122959
复制相似问题