diff --git a/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionManager.java b/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionManager.java index 3d07d3f979..8fb151a945 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionManager.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionManager.java @@ -91,7 +91,7 @@ public final class NonInjectionManager implements InjectionManager { */ private class TypedInstances { private final MultivaluedMap> singletonInstances = new MultivaluedHashMap<>(); - private final ThreadLocal>> threadInstances = new ThreadLocal<>(); + private ThreadLocal>> threadInstances = new ThreadLocal<>(); private final List threadPredestroyables = Collections.synchronizedList(new LinkedList<>()); private final ReentrantLock singletonInstancesLock = new ReentrantLock(); @@ -203,6 +203,8 @@ T getInstance(TYPE clazz, Annotation[] annotations) { void dispose() { singletonInstances.forEach((clazz, instances) -> instances.forEach(instance -> preDestroy(instance.getInstance()))); threadPredestroyables.forEach(NonInjectionManager.this::preDestroy); + /* The java.lang.ThreadLocal$ThreadLocalMap$Entry[] keeps references to this NonInjectionManager */ + threadInstances = null; } }