I’m curious if anyone has had any success implementing a smart resource system in a Java game/engine.
What I’m referring to is a system in which resources are removed from memory (unloaded) once a specific threshold has been surpassed. A resource manager tracks each resource (via a LRU scheme or some such). When a new resource load is requested, the manager checks the threshold and unloads any previously loaded but currently uneeded resources if neccesary. When an active unloaded resource is later requested by the game, the manager loads it after first making room by unloading something else.
Considering that the only way to unload a resource in Java would be to null it and ensure that no references to it exist, I’m concerned about the potential for triggering the gc too often. Additionally, since the nulled reference will still be resident in memory, I’m also concerned about cases where a gc is not triggered - causing a resource to actually be in memory twice (the active, referenced one and the nulled one waiting to be gced).
This sort of system is very useful for games with large terrain sets, oodles of models, and numerous sound effects/music. By dividing the world into zones, only the resources belonging to the current and adjacent zones need be initialized at a given time. And of those, only a subset need actually be resident in memory.
Anyone have any experience with a Java implementation?