You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prevent class loaders from leaking when using ClassValue cache (#2175)
ClassValue can transitively refer to an instance of type java.lang.Class, so this may prevent the loader from being collected during garbage collection.
Using SoftReference over the value should solve this problem.
* A class that combines the capabilities of ClassValue and SoftReference.
56
+
* Softly binds the calculated value to the specified class.
57
+
*
58
+
* [SoftReference] used to prevent class loaders from leaking,
59
+
* since the value can transitively refer to an instance of type [Class], this may prevent the loader from
60
+
* being collected during garbage collection.
61
+
*
62
+
* In the first calculation the value is cached, every time [getOrSet] is called, a pre-calculated value is returned.
63
+
*
64
+
* However, the value can be collected during garbage collection (thanks to [SoftReference])
65
+
* - in this case, when trying to call the [getOrSet] function, the value will be calculated again and placed in the cache.
66
+
*
67
+
* An important requirement for a function generating a value is that it must be stable, so that each time it is called for the same class, the function returns similar values.
68
+
* In the case of serializers, these should be instances of the same class filled with equivalent values.
0 commit comments