When I play my game over some time, I get the following error message:
java.lang.OutOfMemoryError: Direct buffer memory
at java.nio.Bits.reserveMemory(Bits.java:633)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:95)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:288)
at com.jme.util.geom.BufferUtils.createByteBuffer(Unknown Source)
at com.jme.util.TextureManager.loadImage(Unknown Source)
at com.jme.util.TextureManager.loadTexture(Unknown Source)
at com.jme.util.TextureManager.loadTexture(Unknown Source)
at kanjigame.bot.KanjiBot.initBot(KanjiBot.java:62)
KanjiBot is a class that helds a node with a box, and the texture of this box is dynamically created (every bot has another Kanji [Japanese symbol] on it). There come new bots in, and bots are killed and removed. Else there is not much changing in the level, at least not regarding textures. First I thought, that I hold somewherre a reference, which prevents the killed bots from GC. Then I put this code in the bot class:
public void finalize() {
System.out.println("bot killed");
}
...and it was executed -> the bots are really garbage collected. When they are killed, I do this:
node.removeController(...); //for all controllers
node.getParent().detachChild(node);
.. but obviously this is not enough to GC the texture. I can see in the task manager, how the java process increases by about 0.7 MB when a bot is killed and a new one comes in.
Of course, I hold no direct references to the texture or to the node.
Any ideas?