2011-05-10 146 views
0

在程序启动过程中偶尔出现内存异常。堆栈跟踪如下。我只在客户机器上得到这个崩溃。内存不足异常

我应该遵循哪些步骤来确定根本原因?

[369][4/29/2011 18:32:15:343]-ERR -[ThreadId = 7916, UIFramework_ICEVisionPro_GUIExceptionHandler.LogException]-System.OutOfMemoryException: Out of memory. 

    at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) 

    at System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height) 

    at System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle) 

    at System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle) 

    at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle) 

    at System.Windows.Forms.Control.WmPaint(Message& m) 

    at System.Windows.Forms.Control.WndProc(Message& m) 

    at System.Windows.Forms.ScrollableControl.WndProc(Message& m) 

    at System.Windows.Forms.ContainerControl.WndProc(Message& m) 

    at System.Windows.Forms.UserControl.WndProc(Message& m) 

    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 

    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
+0

你正在做任何'位图'对象和处理相同?如果是这样,我相信没有足够的内存可用于执行相同的进程 – V4Vendetta 2011-05-10 07:54:55

+0

您是否处置所有非托管资源? – dandan78 2011-05-10 07:56:52

+0

@ dandan78:我不确定。这是因为有些屏幕是我们开发的,有些是由客户开发的。是否有任何工具可以确定是否在应用程序中的非托管资源上调用了dispose? – Maanu 2011-05-10 08:01:39

回答

2

使用一个体面的内存分析器来帮助查找问题

0

的根本原因,从跟踪上述我知道你正在使用Windows.Forms的。 Windows窗体程序中的内存泄露可能是因为忘记取消订阅关闭表单(订阅者阻止处理表单)的事件。有 a few articlestutorials这表明这是一个在窗体编程中很常见的错误,所以可能你可以检查出来。当然,已经说过,它可能不太适合你的情况(在程序启动时出现mem)。

如果托管代码中发生内存泄漏,使用内存分析器可能是一个好主意。我主要使用的是ANTS Mem Profiler,它具有很好的图表和统计数据,并且比大多数用户界面更友好。

但是,如果泄漏发生在非托管代码(like for this guy here)中,您可以搭便车。 This article可能会帮助你开始。

总而言之,您可能需要大量阅读,试图理解.net应用程序中的内存管理,gc世代如何工作等等,而这一切都会让您花费大量时间。

祝你好运!