JDK 11 | JDK 17 | JDK 18 | JDK 19 |
---|---|---|---|
11.0.16Fixed | 17.0.4Fixed | 18.0.2Fixed | 19 b02Fixed |
Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
The caches in ObjectStreamClass basically map WeakReference<Class> to SoftReference<ObjectStreamClass>, where the ObjectStreamClass also references the same Class. That means that the cache entry, and thus the class and its class-loader, will not get reclaimed, unless the GC determines that memory pressure is very high. However, this seems bogus, because that unnecessarily keeps ClassLoaders and all its classes alive much longer than necessary: as soon as a ClassLoader (and all its classes) become unreachable, there is no point in retaining the stuff in OSC's caches. This can be demonstrated by compiling the attached .java files, and run: java TestObjectStreamClass
|