Reputation: 28084
from time to time I am haunted by the "org.eclipse.swt.SWTError: No more handles". I already know tools like GDIView, to watch the number of handles allocated, but now I wonder if there is a better way to do this.
Is there a tool available? Maybe one that logs all stacktraces when handles are created? And which shows the new handles between two invocation points?
Regards, Daniel
PS: Added the windows tag because dev occures mostly on windows and a windows only tool would be good enough.
Upvotes: 5
Views: 2387
Reputation: 101
Sleak is a good tool but it lacks information about Widget handlers. You can list the Shells, Composites and controls from the Display object. display.getShells(), shell.getChildren(), composite.getChildren(). It is more complicated with menu Widgets that are not bound to a Control. They are listed in the menus array in the Decorations class that the Shell extends but not visible :( To get the full array of menus from the Shell, it can be subclassed to include public Menu [] getMenues() { return menus;}.
Upvotes: 0
Reputation: 574
Sleak seems to be very outdated and I did not get it working. Eventually this will also help someone. Add the following code early in your ui code:
Display.getCurrent().DEBUG = true;
Display.getCurrent().setTracking(true);
Output on close/dispose of the application:
Summary: 930 Font(s), 50 Image(s)
Also a list with stacktraces is outputed with places where resources was allocated.
See Device class source code for further details: https://github.com/eclipse-platform/eclipse.platform.swt/blob/7479681ce2cd75b1adb10220d061d83e4f83e2cd/bundles/org.eclipse.swt/Eclipse%20SWT/cocoa/org/eclipse/swt/graphics/Device.java
Upvotes: 0
Reputation: 28084
I found out about Sleak, a great tool to debug SWT resources! Highly recommended for everyone with the same problems. Even shows the images for image resources!
Upvotes: 3
Reputation: 12350
For me the issue was simply that new Shell() has been called too often. Storing the shell as static member and reusing it helped. Therefore, before applying a tool like Sleak, others might want to do a full text search for "new Shell" and check that they don't have the same simple cause.
Upvotes: 0