I noticed that my game was gobbling up memory like there was no tomorrow, increasing the heap size to up towards 6-700mb at worst. I turned on some profiling to see what was happening, and noticed nifty was creating a tremendous amount of Abstract List objects and HashMap entries.
At this point i looking at a full screen nifty screen with a layer on top of it, showing a couple of images. Nothing in the app(let) is being updated, it’s just rendering the screen.
I don’t know much about what’s going on under the hood of nifty, so i’m looking for a few pointers as to what could be causing this. Surely it can’t be normal? Attaching a few images of the profiler results.
I guess you could say that nifty gui hasn’t been optimized for garbage collection … However if I see the results correctly the AbstractLists and HashMaps only take about 5 MB memory?
Anyways, its possible to avoid generating garbage by simply iterating over the list using a for int loop instead of using an iterator. For the HashMap/HashSet it is possible to create custom optimized classes that do not generate garbage on iteration, jME3 for example has IntMap and ListMap which do not generate garbage, they are used internally for rendering.
As for increasing the heap size, thats what the JVM does automatically unless you limit the heap size. Using -Xmx command.
It is “lazy” when garbage collecting, so it will let garbage pile up until there’s no more space to allocate and then the garbage collector will be invoked.
But there’s a downside to limiting heap size as that means more garbage collection pauses during gameplay, which stutters FPS. It is best if nifty gets optimized instead.
Well wait longer is also bad, as it means a large lag every hour or so when the gc is invoced.
I’m not 100% sure how the profiler works, but it’s set to record every 10 objects, so it might be that they’re actually taking up 50mb. But it seems to be where the action happens, and it seems to be nifty stuff. The other entries are quite constant at that time, and the heap itself is < 100mb during loading/init, and then takes off.