diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 54d8f25d4..383581140 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -53,6 +53,7 @@ public class PGraphicsOpenGL extends PGraphics { // Using the technique alternative to finalization described in: // http://www.oracle.com/technetwork/articles/java/finalization-137655.html static private ReferenceQueue refQueue = new ReferenceQueue<>(); + static private List> reachableWeakReferences = new LinkedList<>(); static final private int MAX_DRAIN_GLRES_ITERATIONS = 10; @@ -73,9 +74,11 @@ public class PGraphicsOpenGL extends PGraphics { protected Disposable(T obj) { super(obj, refQueue); drainRefQueueBounded(); + reachableWeakReferences.add(this); } public void dispose() { + reachableWeakReferences.remove(this); disposeNative(); }