2

I am trying to track down the cause of a Windows-only problem in my SWT application, which sometimes runs into the following error:

org.eclipse.swt.SWTError: No more handles

Tracing the line which throws this error reveals that it's calling the CreateWindowEx Windows API function, which can fail if there is not a GDI handle free.

The error occurs periodically when running tests against the application on one of our Windows Server 2008 build servers, over Remote Desktop.

I have so far found and fixed a number of leaks of SWT Image and Font objects, some of them resulting in hundreds of GDI handles leaked per invocation of the application.

However, I am struggling to verify (using a test application which deliberately uses lots of handles) that I've fixed the problem. My test application hits the per-process limit of 10,000 GDI handles. Running it serially doesn't cause a problem; running two or three of it simultaneously does.

So, at last comes my question:

Is it possible, under any circumstances, for a GDI handle on Windows to outlive the process which created it?

If so, is there a tool I can use to view the count of these 'leaked' GDI handles?

David North
  • 1,247
  • 1
  • 14
  • 32
  • 2
    If you're failing on CreateWindowEx, then you're failing to get an HWND, which is a USER handle, not a GDI handle. Both USER and GDI typically have a limit of 10,000 objects (each) per process, and neither kind of object can outlive the process that created them. – Adrian McCarthy Jan 31 '13 at 16:59
  • I had similar problems with SWT images in an application and I used [VisualVM](http://visualvm.java.net/) to figure it out. For that I didn't care about the GDI handles, instead I took a closer look where all those thousands of `org.eclipse.swt.graphics.Image` instances came from. – jens-na Feb 01 '13 at 09:27

0 Answers0