-
Enhancement
-
Resolution: Unresolved
-
P4
-
jfx11, 8, 9, 10
-
Cause Known
PredefinedMeshManager uses class instances to store mesh caches. An enum based approach will eliminate code duplication and provide the bundled advantages of enums.
enum TriangleMeshCache {
BOX_CACHE, SPHERE_CACHE, CYLINDER_CACHE;
Map cache = new HashMap(...);
// methods
}
This will allow an extremely easy and safe way to add more shape caches in the future if the need arises.
A disadvantage is that once one of the cache instances is lazily initialized, the other caches will be initialized as well. This is only a minor disadvantage as each instance will only hold an empty map, and given that there is a very limited number of predefined shapes that can be added, the memory consumption overhead is very limited.
This is also an opportunity to revisit the disputable caching mechanism of reference counts, as noted in a comment onJDK-8192056 [1].
Also, the Map's constructor parameters should be relooked at - is there a performance reason to use something other than the default? There is a TODO there.
Shape3D and its subclasses can also be refactored to remove repeating code along with the necessary changes for the above.
[1] https://bugs.openjdk.java.net/browse/JDK-8192056?focusedCommentId=14148930&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14148930
enum TriangleMeshCache {
BOX_CACHE, SPHERE_CACHE, CYLINDER_CACHE;
Map cache = new HashMap(...);
// methods
}
This will allow an extremely easy and safe way to add more shape caches in the future if the need arises.
A disadvantage is that once one of the cache instances is lazily initialized, the other caches will be initialized as well. This is only a minor disadvantage as each instance will only hold an empty map, and given that there is a very limited number of predefined shapes that can be added, the memory consumption overhead is very limited.
This is also an opportunity to revisit the disputable caching mechanism of reference counts, as noted in a comment on
Also, the Map's constructor parameters should be relooked at - is there a performance reason to use something other than the default? There is a TODO there.
Shape3D and its subclasses can also be refactored to remove repeating code along with the necessary changes for the above.
[1] https://bugs.openjdk.java.net/browse/JDK-8192056?focusedCommentId=14148930&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14148930
- is blocked by
-
JDK-8192056 Memory leak when removing javafx.scene.shape.Sphere-objects from a group or container
-
- Resolved
-