在我的VB.Net应用程序中运行时,我遇到了错误。这个错误并不总是出现,所以我也无法重现它。也没有确切的顺序可以重现这个错误。
错误信息如下:
System.OutOfMemoryException: 内存不足。 at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) at System.Windows.Forms.ToolStrip.OnPaint(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) 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.ToolStrip.WndProc(Message& m) at System.Windows.Forms.StatusStrip.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)
错误描述:
MyApplication_UnhandledException
在这个错误后,我收到一条消息,上面写着:"内存不足,无法创建位图。关闭一个或多个应用程序以增加可用内存。"
当我检查应用程序的内存使用情况时,并没有那么高。这个错误不会反复出现。那我该如何解决这个问题?如何进行故障排除?我尝试使用.NET和Redgate内存分析器来运行我的应用程序。
下面是一个未管理内存使用量的屏幕截图。我不确定这些值是否很高。
更新:
错误信息如下:
System.OutOfMemoryException: 内存不足。 at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc) at System.Windows.Forms.ToolStrip.OnPaint(PaintEventArgs e) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) 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.ToolStrip.WndProc(Message& m) at System.Windows.Forms.StatusStrip.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)
错误描述:
MyApplication_UnhandledException
在这个错误后,我收到一条消息,上面写着:"内存不足,无法创建位图。关闭一个或多个应用程序以增加可用内存。"
当我检查应用程序的内存使用情况时,并没有那么高。这个错误不会反复出现。那我该如何解决这个问题?如何进行故障排除?我尝试使用.NET和Redgate内存分析器来运行我的应用程序。
下面是一个未管理内存使用量的屏幕截图。我不确定这些值是否很高。
更新:
我再次遇到了错误。检查了GDI对象,发现有9998个。因此,错误是由于GDI对象过多引起的。现在问题是如何解决。然后我使用了GDIView工具进行了检查。通过该工具,我得到了pen-2954 brush-5918 font-90 bitmap-13等等总共9998个GDI。那么这些pen和brush是什么呢?在我的代码中,我没有使用brush或pen(我搜索了代码中的“pen”和“brush”,但没有找到)。所以请帮助我解决这个问题。