【发布时间】:2013-07-17 13:24:37
【问题描述】:
在我的一个 VB.Net 应用程序中,我在运行该应用程序时遇到错误。这个错误并不总是出现。所以我也无法重现该错误。也没有确切的顺序来重现错误。
堆栈:System.OutOfMemoryException:内存不足。 在 System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) 在 System.Windows.Forms.ToolStrip.OnPaint(PaintEventArgs e) 在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16 层,布尔 disposeEventArgs) 在 System.Windows.Forms.Control.WmPaint(消息和 m) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.ScrollableControl.WndProc(消息和 m) 在 System.Windows.Forms.ToolStrip.WndProc(消息和 m) 在 System.Windows.Forms.StatusStrip.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
错误描述:
MyApplication_UnhandledException
在这个错误之后,我收到一条消息说,
内存不足,无法创建位图。关闭一个或多个应用程序以增加可用性。
当我检查应用程序的内存使用情况时,它并没有那么高。此错误不会重复出现。那么我该如何解决这个错误。如何解决? 我使用 .Net 内存分析器和 redgate 内存分析器检查了我的应用程序的运行情况。
以下是非托管内存使用量的屏幕截图。我不知道这些值是否很高。
更新:
我又得到了错误。检查了 gdi 对象,它是 9998。所以错误是由于高 gdi 对象造成的。现在问题是如何解决。然后我使用GDIView 并检查。通过那个工具我得到了笔-2954 画笔 5918 字体 90 位图 13 等 GDI 总计 9998 那么这些钢笔和画笔是什么?在我的代码中,我没有使用画笔或钢笔。(我在代码中搜索了“钢笔”和“画笔”但没有得到任何东西。)所以请帮助我
【问题讨论】:
-
你为 Tooltip 分配了什么?
-
您能出示您的代码吗?最好是一些与位图一起使用的部分?
-
唯一明显的是您大量使用 ActiveX 控件。这可以防止垃圾收集器经常运行以使您摆脱麻烦。当您不在 System.Drawing 对象上使用 Dispose() 时遇到的那种麻烦。当你用完太多手柄时,它会像这样爆炸。
标签: vb.net memory-management error-handling out-of-memory