From 2d7b11f73a13f554f1bfa307d248206d21f06bfa Mon Sep 17 00:00:00 2001 From: jansupol Date: Thu, 1 Aug 2024 11:45:02 +0200 Subject: [PATCH] Release a reference to threadlocal on shutdown Signed-off-by: jansupol --- .../jersey/client/innate/inject/NonInjectionManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 8bd511235d..cc3b8eacad 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -90,7 +90,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 List> _getSingletons(TYPE clazz) { @@ -195,6 +195,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; } }