Bug 1029

Summary: Memory leak in GLDrawableHelper: 'perThreadInitAction' shall use a WeakReference
Product: [JogAmp] Jogl Reporter: Bart Adams <bart.adams>
Component: openglAssignee: Sven Gothel <sgothel>
Status: RESOLVED FIXED    
Severity: enhancement CC: askinner
Priority: ---    
Version: 2   
Hardware: All   
OS: all   
Type: --- SCM Refs:
876a168f6757454e8a02543b53e32b89e54282bd
Workaround: ---

Description Bart Adams 2014-07-08 12:44:37 CEST
GLDrawableHelper keeps a ThreadLocal variable:

private static final ThreadLocal<Runnable> perThreadInitAction = new ThreadLocal<Runnable>();

The init action in GLCanvas and GLJPanel are defined as anonymous classes (hence keeping a reference to the canvas or panel itself).

It looks like these init actions are kept in above ThreadLocal variable, even after disposing the GLCanvas or GLJPanel, leading to a memory leak as long as the ThreadLocal variable keeps the runnable.
Comment 1 Sven Gothel 2014-07-28 00:48:44 CEST
Commit 876a168f6757454e8a02543b53e32b89e54282bd:

Static ThreadLocal 'perThreadInitAction' leaks memory if using a hard reference,
utilizing a WeakReference allows the passed 'initAction' owner to be garbage collected.
Comment 2 Sven Gothel 2014-07-29 04:06:35 CEST
Note-1:

It has to be noted, that the static ThreadLocal storage 
within GLDrawableHelper originally did not get released 
in case of AWT, since the GLDrawableHelper instance is 
a member of GLCanvas/GLJPanel and used from within the 
AWT-EDT, which does not die.