-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of (boxed) Integer in ArrayCache.java doesn't work with interning #484
Comments
Hey, On your proposed fix, wouldn't it be sufficient to explicitly use I'll have to investigate this and I also have some other problems I need to take care of first, but if you want to provide a PR addressing this I would gladly merge it. |
You're right that you could use the Integer constructor to get around the interning, however I think this would be less clear / self describing. Also the Integer constructor is deprecated from Java 9. |
I would also like to be able to replace the Ralph pointed me to this thread and noted that @ennerf might already have thoughts on this. Can you maybe comment?
I guess an interface that can provide a cache for all types is needed then – seems like ArrayCache is already halfway there. How about a way to specify a |
There is some more discussion and another proof of concept implementation in #370. |
I do agree DoubleArrayCache has other properties I would like to change unrelated to this issue. Using soft references and a linear lookup time for arrays is very undesirable in my usage (points appended live over time) as the cache can build up to very large and expensive to access. I already have to periodically clear the DoubleArrayCache to avoid significant performance regressions. If this were behind an interface and could optionally be specified to the renderer I could provide an implementation which better suits my needs. |
Because the JVM caches Integer objects, if Integer is useed as the key of a weak HashMap, some entries will never be released. This commit changes to use a ArrayCacheSizeKey type, which does not have interning. This is prefered to creating unique Integer instances with `new` as this constructor is deprecated. fixes #484
Because the JVM caches Integer objects, if Integer is useed as the key of a weak HashMap, some entries will never be released. This commit changes to use a ArrayCacheSizeKey type, which does not have interning. This is prefered to creating unique Integer instances with `new` as this constructor is deprecated. fixes #484
Because the JVM caches Integer objects, if Integer is useed as the key of a weak HashMap, some entries will never be released. This commit changes to use a ArrayCacheSizeKey type, which does not have interning. This is prefered to creating unique Integer instances with `new` as this constructor is deprecated. fixes #484
Because the JVM caches Integer objects, if Integer is useed as the key of a weak HashMap, some entries will never be released. This commit changes to use a ArrayCacheSizeKey type, which does not have interning. This is prefered to creating unique Integer instances with `new` as this constructor is deprecated. fixes #484
Because the JVM caches Integer objects, if Integer is useed as the key of a weak HashMap, some entries will never be released. This commit changes to use a ArrayCacheSizeKey type, which does not have interning. This is prefered to creating unique Integer instances with `new` as this constructor is deprecated. fixes #484
Because the JVM caches Integer objects, if Integer is useed as the key of a weak HashMap, some entries will never be released. This commit changes to use a ArrayCacheSizeKey type, which does not have interning. This is prefered to creating unique Integer instances with `new` as this constructor is deprecated. fixes #484
Because the JVM caches Integer objects, if Integer is useed as the key of a weak HashMap, some entries will never be released. This commit changes to use a ArrayCacheSizeKey type, which does not have interning. This is prefered to creating unique Integer instances with `new` as this constructor is deprecated. fixes #484
ArrayCache.java uses multiple ConcurrentMap<String, WeakHashMap<Integer, ARRAY>> to cache and potentially re-use them.
e.g.
The Integer keys within the inner WeakHashMap are created by auto-boxing of primitive int arguments passed in, either explicitly for the get* methods, or from the array length value for the release methods.
Integer has an internal caching/interning mechanism to avoid boxing costs. This interning can be controlled via. a system property (java.lang.Integer.IntegerCache.high) to increase the size of the cache. When using ChartFX increasing this cache size can reduce various boxing costs - e.g. style & label maps which use Integer keys.
However increasing this cache size can then cause a build-up of arrays (and their contents - e.g. the String[]s can then contribute significant memory pressure) within ArrayCache.java - since the boxed Integers are cached with strong references the ArrayCache WeakHashMaps then never evict.
ArrayCache.java should not use Integer in the WeakHashMaps.
Assuming you want to keep the same pattern but with fewer gotchas ArrayCache.java should define a class equivalent to Integer (wrapping a primitive int) but with a controlled life-cycle (presumably no interning) to use as keys in the WeakHashMaps.
The text was updated successfully, but these errors were encountered: