When profiling our game I noticed that a lot of memory garbage is created by RenderDeviceJme.
For example the method renderImage() is called a lot to draw multiple nifty elements each frame. Here the method quad.clearBuffer() is called that creates a new ArrayList inside the getBuffer() method of the SafeArrayList (line 141).
- Is it possible to prevent SafeArrayList from creating new ArrayLists so often or am I doing something wrong?
- And/Or maybe it’s possible to cache part of renderImage() method (other parts also create garbage) in the same way that renderFont() does this with “textCacheCurrentFrame”?
I also noticed that @nehon was optimizing the “setColor”, thxs!
the point of SafeArrayList is that you get a new array… Whats the issue? Java is built to work with young generation garbage very efficiently (repeat, java, not dalvik).
The issue is the large amount of garbage that is created. Yes the GC can collect this, however each time the GC runs it can slow down the game. So I would prefer to minimize the amount of garbage created.
I understand that this might not be possible for the SafeArrayList. But maybe it is possible to add a hashmap Cache like the one in renderFont()?
As I said, the young generation is cleared very quickly in java. Its performance is comparable to the C stack as java effectively has no stack that could be utilized by the user. So if an object is created in a “stack like” situation there is really no need to worry about these.