Hi everybody,
out of curiosity I monitored the memory usage of my game engine and noticed that it's memory usage rises at a rate of about 4k/second (task manager, Windows 7 x64). So far the program only consists of an entity/component system and a simple game class for testing. Essentially my game loop looks like this:
1 2 3 4 5 6 7 8 9 10 11 12
| void gameLoop() { if (scene == null) throw new RuntimeException("Critical: Game.scene must not be null."); millisPassed = System.currentTimeMillis(); while (!gameEnd) { fdelta = (System.currentTimeMillis() - millisPassed) / 1000f; scene.update(fdelta); scene.render(fdelta); millisPassed = System.currentTimeMillis(); calculateFps(); yield(); } } |
I already found out that when commenting the scene.update and scene.render method calls out the memory usage is constant, but the only thing I do in those methods is iterating over an empty ArrayList<Entity>:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public class Scene implements IScene {
protected ArrayList<Entity> entities;
public Scene() { entities = new ArrayList<Entity>(); }
[...]
@Override public void update(final float fdelta) { for (Entity entity : entities) entity.update(fdelta); }
@Override public void render(final float fdelta) { for (Entity entity : entities) entity.render(fdelta); } } |
In their update and render method entities then call the update/render methods of their respective components which do the actual updating/rendering. As already mentioned the program currently iterates over an empty list of entities, so I don't understand why the memory usage increases constantly.
It's not a dramatic increase, from initially 6,000 KB it goes up to 15,000 in about half an hour, but it still concerns me as I assume that it'll be much harder to find the reason for this when my engine is actually doing something.
Here are the Entity's update and render methods:
1 2 3 4 5 6 7 8 9
| public void render(final float fdelta) { for (IRenderCallback c : renderers) c.render(fdelta); }
public void update(final float fdelta) { for (IUpdateCallback c : updates) c.update(fdelta); } |
I'm new to java and have no clue if this behaviour is normal or what causes it, so I hope you guys can explain it to me.
Thanks in advance!