Login  Register

JOGL SWT GLCanvas leaks SWT Color

Posted by badjames on Mar 31, 2025; 2:41pm
URL: https://forum.jogamp.org/JOGL-SWT-GLCanvas-leaks-SWT-Color-tp4043707.html

Hi,

When running my application using the SWT "S-Leak" utility, it shows there is a leak of an SWT Color resource when the SWT GLCanvas is created:

java.lang.Error
        at org.eclipse.swt.graphics.Device.new_Object(Device.java:854)
        at org.eclipse.swt.graphics.Resource.init(Resource.java:89)
        at org.eclipse.swt.graphics.Color.<init>(Color.java:89)
        at com.jogamp.opengl.swt.GLCanvas.<init>(GLCanvas.java:385)

Looking at the source code at that line, it seems to verify this:

com/jogamp/opengl/swt/GLCanvas.java:

383:      // Bug 1362 fix or workaround: Seems SWT/GTK3 at least performs lazy initialization
384:      // Minimal action required: setBackground of the parent canvas before reparenting!
385:      setBackground(new Color(parent.getDisplay(), 255, 255, 255));

At line 385, the color is allocated and the reference is lost.  SWT does not take ownership of resources when passed into functions such as setBackground - it is the responsibility of the caller to release the resource when no longer needed.

This was using the latest 2.5.0 build.

Thanks!

James