A computed value produced by a ClassValue instance should not strongly refer to that instance, for example:
class Holder {
Object o;
Holder(Object o) { this.o = o; }
}
class MyClassValue extends ClassValue<Holder> {
Holder computerValue(Class<?> type) {
return new Holder(this);
}
}
In the current JDK implementation this will prevent classes from being garbage collected and therefore cause a memory link.
Rather than changing the implementation of ClassValue to support such an edge case it is preferred to update the documentation of ClassValue.computeValue warning against such behaviour.
class Holder {
Object o;
Holder(Object o) { this.o = o; }
}
class MyClassValue extends ClassValue<Holder> {
Holder computerValue(Class<?> type) {
return new Holder(this);
}
}
In the current JDK implementation this will prevent classes from being garbage collected and therefore cause a memory link.
Rather than changing the implementation of ClassValue to support such an edge case it is preferred to update the documentation of ClassValue.computeValue warning against such behaviour.
- relates to
-
JDK-8136353 ClassValue preventing class unloading
-
- Closed
-