2

I'm having some weird OutOfMemory exception.

We have an application, that basically draws some charts for data coming from some hardware devices.

If I run the application with the MemoryProfiler, after some time, I got some OutOfMemoryException. We know this same exception happens to some of our customers, even without debugger.

The weird part:

  • We have still plenty of free memory space
  • When having this exception, the application was only using 360MB

We are using Nevron library to draw charts, the exception we get is:

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)

We are using DevExpress for every other part of the application. We managed to get also this error from them(I'm not sure they are related, but I've the feeling they do):

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)

We have a "catch all exception" handler that allow the application to not close after the exception. Currently this is the effect on the GUI(where it is located depends on where the exception happens:

Exception effect

Here is my Memory Profiler session: enter image description here

Here is the GDIView situation at the moment of the crash(the counter are increasing/decreasing all the time, not by much, but usually, when the GC run I'm back to an 0 offset.): enter image description here

What I've already checked:

  • ANTS profiler doesn't warn me about LOH fragmentation on snapshot taken just before and just after this exception
  • I don't see big memory increase(memory leak)
  • I've still plenty of space
  • I don't have an HUGE usage of GDI handle(Checked with GDIView)

I'm kind of hopeless since this exception is happening to our customer, on my computer(I can reproduce it, but not easily), but I can't understand what is going wrong here, everything on internet I found is about having GDI handle growing(or having the GDI handles of another application growing), but it doesn't seems to be the case.

This error seems to always happens with things directly in contact of the GUI, even if when we receive data, we have to allocate big arrays(not that big, but quite often).

What can I do to have more information on this exception?

Things I already found:

  • TestLimit which allows me to create more than 16 millions of new handles
  • This SO question, but here I'm unable to find some clue of increasing handle
  • This article but I checked, all my new Graphic are disposed(no idea for the ones of the library
  • This article on LOH, but according to ANTS, it doesn't seems to be my problem

I reported this issue to Nevron/DevExpress, but not sure they can help, and no answer for now.

EDIT

I did manage once to have ANTS telling me this:

enter image description here

But, I'm not sure I should consider it, because the unusable space is very low, and I've still plenty of memory space(Is there a size limit for the LOH?)

Community
  • 1
  • 1
J4N
  • 19,480
  • 39
  • 187
  • 340

0 Answers0