OutOfMemoryError

Started by mystara, May 03, 2008, 05:24:32 PM

Previous topic - Next topic

mystara

Hello,

I've been experiencing OutOfMemory (heap) errors in my application when I repeatedly create a new world object and populate it (with the same objects each time). To my knowledge, this can only really be caused by some kind of memory leak. As the memory used before and after the world is recreated should be identical.

In trying to track down this problem, the only clue I've discovered is that preventing rendering of my world object seems to remove the OutOfMemory error. The function which, when removed from my main loop, eliminates the OutOfMemoryError is as follows:


public void renderWorld()
{
if (switchMode != 0)
switchOptions();

World theWorld = gstate.getWorld();

buffer.clear();
theWorld.renderScene(buffer);

if (!wireframe)
theWorld.draw(buffer);
else
theWorld.drawWireframe(buffer, Color.white);

buffer.update();
display();
}


Any clues as to why this might be causing problems if the world and camera are changed by another object? Anything obviously amiss?
Or any ideas as to how to find this stupid error?

Other hints welcome :P

EgonOlsen

That should not happen...can you create a simple test case that shows this problem?

mystara

It's entirely reproducable in my own code. Though it's very large, and it's entirely possible that something else is going wrong though. That's why I was wondering if there was an easy way to locate the source of the leak.

But I'll see if I can combine the bits together

mystara

Ah,

It was easier than I thought to reproduce.
I have emailed the Java source to you.

NB: I can't seem to determine what version of JPCT I'm using. It's either 1.5 or 1.4, but I suspect it's 1.5

Cheers!

EgonOlsen

Quote from: mystara on May 03, 2008, 07:02:26 PM
I have emailed the Java source to you.
I haven't received anything yet.. ???

EgonOlsen

Still no mail from you...i tried to reproduce this problem myself but creating/populating/rendering dozens of worlds one after the other, but there was a leak in that case.

Edit: Mail is here now...it took over an hour. Strange...

EgonOlsen

I see...with your example code, i can reproduce the problem. It's a memory leak in the visibility list management. However, there is no workaround ATM, so you've to live with that until the new version is final (next week, i hope). I'll add a fix to that version. Unfortunately i have to add a dispose()-method to World to fix this. I'll also add it to finalize(), which may help to fix this for older applications, but as we all know, finalize() shouldn't be used for such things, because...blah...blah....i'll add it anyway.

Thanks for pointing this out.

EgonOlsen

I've just released 1.16 final. It includes the dispose()-method in World. That should help to prevent the error.

mystara