From 79833c9e4741bec9d1f56ea8b322679756b16f70 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 31 Dec 2019 05:45:00 +0100 Subject: Bug 1312: GLContextShareSet: Utilize WeakIdentityHashMap for shareMap and its destroyedShares Picking up Tom Nuydens suggestion to utilize a WeakIdentityHashMap instead of a IdentityHashMap, allowing destroyed GLContext to be removed from the GLContextShareSet through the GC. TestSharedContextVBOES2NEWT5 demonstrates the use-case, having one master context and several slaves being spawn off, killed and new sets to be spawn off. Here the GLContextShareSet shall not hard-reference the destroyed and user-unreferenced context, but allowing the system to GC 'em. --- src/jogl/classes/jogamp/opengl/GLContextShareSet.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/jogl') diff --git a/src/jogl/classes/jogamp/opengl/GLContextShareSet.java b/src/jogl/classes/jogamp/opengl/GLContextShareSet.java index 3a6502e1a..e366334b1 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextShareSet.java +++ b/src/jogl/classes/jogamp/opengl/GLContextShareSet.java @@ -47,6 +47,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; +import com.jogamp.common.util.WeakIdentityHashMap; import com.jogamp.opengl.GLContext; import com.jogamp.opengl.GLException; @@ -61,11 +62,11 @@ public class GLContextShareSet { // This class is implemented using a HashMap which maps from all shared contexts // to a share set, containing all shared contexts itself. - private static final Map shareMap = new IdentityHashMap(); + private static final Map shareMap = new WeakIdentityHashMap(); private static class ShareSet { private final Map createdShares = new IdentityHashMap(); - private final Map destroyedShares = new IdentityHashMap(); + private final Map destroyedShares = new WeakIdentityHashMap(); public final void mapNewEntry(final GLContext slave, final GLContext master) { final GLContext preMaster; -- cgit v1.2.3