Right now every SceneGraphObject has its own UserObject HashMap. This seems heavy on memory, as each SceneGraphObject must allocate an extra 4-8 bytes even for a null pointer (if my understanding of Java memory is correct
http://www.javaspecialists.co.za/archive/Issue029.html.) Not only that but a HashMap isn't really a lightweight object.
What I've done in my project is created what I call "XithDataStore" it stores a WeakHashMap (so no memory leaks) from the SceneGraphObject to "XithData." The XithData object is with a bunch of setters and getters.
To maintain backwards compatibility, if the user were to do a setUserData(key, value) it could create the HashMap and store that in the WeakHashMap.
I've rethought this. And it won't work as a default implementation as back storage for all SceneGraphObjects' user objects for two reasons:
1. The key for a user object is an object. So we can't prefix it with a node local information. Therefore we cannot use one big map for all SGOs to store arbitrary data. Of course this will work like you did it. But this can't be implemented directly in the xith API, since we cannot assume a certain storage type.
2. The WeakHashMap removes entries from the map when no other pointer exists to the mapped object. This is an absolute no-go and I am pretty sure, that this is even not the behavior, that you need in your app.
The current solution is not that bad, since the HashMap is instatiated when it is needed (not earlier). So there's just this one null pointer per SGO (8 bytes), that I really wouldn't worry about. A node is a lot bigger than just 8 bytes. So this is just a small piece of the cake.
Of course I am very open, if you have a better solution, that will actually work.
Marvin