[英]GDI-Handle Leak
I got a problem with GDI-Handle´s. 我遇到了GDI-Handle的问题。 I understand that windows limit´s the amount of GDI-Handles per application at 10.000.
我知道Windows限制每个应用程序的GDI句柄数量为10.000。 Then the application crashes.
然后应用程序崩溃。
On my own system and several virtual machines the amount of GDI-Handles stays between 300 and 500... no matter what I do. 在我自己的系统和几个虚拟机上,无论执行什么操作,GDI句柄的数量都保持在300到500之间。 On a customer project it is getting higher and higher till it reaches 10.000 after some days.
在客户项目上,它越来越高,直到几天后达到10.000。
13.06.2013: 12:47 GDI-Handles 1550
13.06.2013: 12:59 GDI-Handles 1553
13.06.2013: 13:07 GDI-Handles 1557
13.06.2013: 13:55 GDI-Handles 1564
13.06.2013: 15:29 GDI-Handles 2193
13.06.2013: 16:47 GDI-Handles 2201
13.06.2013: 17:14 GDI-Handles 2201
13.06.2013: 17:21 GDI-Handles 2201
13.06.2013: 17:29 GDI-Handles 2263
Why is the behavior on another pc with the exactly same .NET application so different? 为什么在具有完全相同的.NET应用程序的另一台PC上的行为如此不同? Any idea how i can debug it without visual studio installed on the system?
不知道我如何在不安装Visual Studio的情况下调试它吗?
I solved the problem. 我解决了问题。 On the system I got the bug I ran the tool "GDIView".
在系统上,我得到了运行工具“ GDIView”的错误。 With this tool I was able to determine that the problem-causing object is a Bitmap.
使用此工具,我能够确定导致问题的对象是位图。 I found the Bitmap causing the trouble and fount out that I have to dispose IntPtr manually (no help from the GC there).
我发现位图引起了麻烦,并发现必须手动处理IntPtr(那里的GC没有帮助)。
ImageSource wpfBitmap = null;
if (this.buttonImage != null)
{
IntPtr hBitmap = this.buttonImage.GetHbitmap();
wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap(
hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
DeleteObject(hBitmap);
}
return wpfBitmap;
So I just added the "DeleteObject()" method and the leak was gone. 因此,我只添加了“ DeleteObject()”方法,泄漏就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.