Thomas S.
Thomas S.

Reputation: 6345

Reasons for "no more handles"

For our SWT-based application we've got certain different SWT crash reports where SWT crashes with "no more handles" errors. This only happens for very few people and sometimes in a very early stage of launching the application. A typical stacktrace of the very early application state looks like this:

Caused by: org.eclipse.swt.SWTError: No more handles
    at org.eclipse.swt.SWT.error(SWT.java:4467)
    at org.eclipse.swt.SWT.error(SWT.java:4356)
    at org.eclipse.swt.SWT.error(SWT.java:4327)
    at org.eclipse.swt.widgets.Widget.error(Widget.java:476)
    at org.eclipse.swt.widgets.TaskBar.createHandle(TaskBar.java:103)
    at org.eclipse.swt.widgets.TaskBar.<init>(TaskBar.java:96)
    at org.eclipse.swt.widgets.Display.getSystemTaskBar(Display.java:2567)
    ...

We already have tested our application and under normal conditions it does not leak any resources (fonts, colors, images, GCs, ...), the values in the Windows Task Manager (Handles, USER Objects, GDI Objects, ...) are only in the top third, but often not the top most ones.

What reasons could cause such problems - could it be a machine with a lot of applications running, other possibly debugged applications leak massive resources, what else? What information, e.g. output of "tasklist.exe" I need to request from the users to get a clue for a possible reason?

Upvotes: 2

Views: 2654

Answers (1)

andi
andi

Reputation: 922

I just got the same crash report. To investigate deeper, the following code can be used:

import org.eclipse.swt.internal.win32.OS;
import org.eclipse.swt.widgets.Display;

public class InvestigateSwtProblem {

    static final byte[] CLSID_TaskbarList = new byte[16];
    static final byte[] IID_ITaskbarList3 = new byte[16];

    static {
        OS.IIDFromString("{56FDF344-FD6D-11d0-958A-006097C9A090}\0".toCharArray(), CLSID_TaskbarList); //$NON-NLS-1$
        OS.IIDFromString("{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}\0".toCharArray(), IID_ITaskbarList3); //$NON-NLS-1$
    }

    public static void main(String[] args) {
        Display display = new Display();

        int /*long*/[] ppv = new int /*long*/ [1];
        int hr = OS.CoCreateInstance(CLSID_TaskbarList, 0, OS.CLSCTX_INPROC_SERVER, IID_ITaskbarList3, ppv);
        System.out.println("Result of CoCreateInstance = " + hr);
    }
}

In my case, the error was -2147024882, which I found in winerror.h to be:

//
// MessageId: E_OUTOFMEMORY
//
// MessageText:
//
// Ran out of memory
//
#define E_OUTOFMEMORY                    _HRESULT_TYPEDEF_(0x8007000EL)

I still don't know the reason or the solution, but at least you have something to tell the sysadmin.

PS. this if for 32 bit SWT. I haven't tested on 64 bit SWT, but I guess you should replace int with long where int /*long*/ appears in the code.

Upvotes: 1

Related Questions