Bug 1029 - Memory leak in GLDrawableHelper: 'perThreadInitAction' shall use a WeakReference
Summary: Memory leak in GLDrawableHelper: 'perThreadInitAction' shall use a WeakReference
Status: RESOLVED FIXED
Alias: None
Product: Jogl
Classification: JogAmp
Component: opengl (show other bugs)
Version: 2
Hardware: All all
: --- enhancement
Assignee: Sven Gothel
URL:
Depends on:
Blocks:
 
Reported: 2014-07-08 12:44 CEST by Bart Adams
Modified: 2014-07-29 04:06 CEST (History)
1 user (show)

See Also:
Type: ---
SCM Refs:
876a168f6757454e8a02543b53e32b89e54282bd
Workaround: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.