aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-07-28 00:47:33 +0200
committerSven Gothel <[email protected]>2014-07-28 00:47:33 +0200
commit876a168f6757454e8a02543b53e32b89e54282bd (patch)
treefa197cecfd8bb0d73fbcc0d2db505d56232e5cee /src/jogl/classes
parent15b9e36e80d6f62f7dfb5c45d00cd04de2007ee5 (diff)
Bug 1029 - Memory leak in GLDrawableHelper: 'perThreadInitAction' shall use a WeakReference
Static ThreadLocal 'perThreadInitAction' leaks memory if using a hard reference, utilizing a WeakReference allows the passed 'initAction' owner to be garbage collected.
Diffstat (limited to 'src/jogl/classes')
-rw-r--r--src/jogl/classes/jogamp/opengl/GLDrawableHelper.java27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
index ad1b9a556..7d05174ce 100644
--- a/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
+++ b/src/jogl/classes/jogamp/opengl/GLDrawableHelper.java
@@ -40,6 +40,7 @@
package jogamp.opengl;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
@@ -1066,7 +1067,21 @@ public class GLDrawableHelper {
return exclusiveContextThread;
}
- private static final ThreadLocal<Runnable> perThreadInitAction = new ThreadLocal<Runnable>();
+ private static final ThreadLocal<WeakReference<Runnable>> perThreadInitAction = new ThreadLocal<WeakReference<Runnable>>();
+ private static final Runnable getLastInitAction() {
+ final WeakReference<Runnable> lastInitActionWR = perThreadInitAction.get();
+ if( null != lastInitActionWR ) {
+ final Runnable lastInitAction = lastInitActionWR.get();
+ if( null == lastInitAction ) {
+ perThreadInitAction.set(null);
+ }
+ return lastInitAction;
+ }
+ return null;
+ }
+ private static final void setLastInitAction(final Runnable initAction) {
+ perThreadInitAction.set(new WeakReference<Runnable>(initAction));
+ }
/** Principal helper method which runs a Runnable with the context
made current. This could have been made part of GLContext, but a
@@ -1128,7 +1143,7 @@ public class GLDrawableHelper {
lastContext = null;
} else {
// utilize recursive locking
- lastInitAction = perThreadInitAction.get();
+ lastInitAction = getLastInitAction();
lastContext.release();
}
}
@@ -1202,7 +1217,7 @@ public class GLDrawableHelper {
lastContext = null;
} else {
// utilize recursive locking
- lastInitAction = perThreadInitAction.get();
+ lastInitAction = getLastInitAction();
lastContext.release();
}
}
@@ -1217,7 +1232,7 @@ public class GLDrawableHelper {
}
if (GLContext.CONTEXT_NOT_CURRENT != res) {
try {
- perThreadInitAction.set(initAction);
+ setLastInitAction(initAction);
if (GLContext.CONTEXT_CURRENT_NEW == res) {
if (DEBUG) {
System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running initAction");
@@ -1291,7 +1306,7 @@ public class GLDrawableHelper {
lastContext = null;
} else {
// utilize recursive locking
- lastInitAction = perThreadInitAction.get();
+ lastInitAction = getLastInitAction();
lastContext.release();
}
}
@@ -1315,7 +1330,7 @@ public class GLDrawableHelper {
}
if (GLContext.CONTEXT_NOT_CURRENT != res) {
try {
- perThreadInitAction.set(initAction);
+ setLastInitAction(initAction);
if (GLContext.CONTEXT_CURRENT_NEW == res) {
if (DEBUG) {
System.err.println("GLDrawableHelper " + this + ".invokeGL(): Running initAction");