Author Topic: OutOfMemoryError  (Read 5848 times)

Offline mystara

  • int
  • **
  • Posts: 79
    • View Profile
OutOfMemoryError
« on: May 03, 2008, 05:24:32 pm »
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:

Code: [Select]
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: OutOfMemoryError
« Reply #1 on: May 03, 2008, 06:18:06 pm »
That should not happen...can you create a simple test case that shows this problem?

Offline mystara

  • int
  • **
  • Posts: 79
    • View Profile
Re: OutOfMemoryError
« Reply #2 on: May 03, 2008, 06:45:59 pm »
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

Offline mystara

  • int
  • **
  • Posts: 79
    • View Profile
Re: OutOfMemoryError
« Reply #3 on: May 03, 2008, 07:02:26 pm »
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!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: OutOfMemoryError
« Reply #4 on: May 03, 2008, 07:09:10 pm »
I have emailed the Java source to you.
I haven't received anything yet.. ???

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: OutOfMemoryError
« Reply #5 on: May 03, 2008, 08:03:10 pm »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: OutOfMemoryError
« Reply #6 on: May 03, 2008, 09:14:00 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11744
    • View Profile
    • http://www.jpct.net
Re: OutOfMemoryError
« Reply #7 on: May 05, 2008, 06:19:01 pm »
I've just released 1.16 final. It includes the dispose()-method in World. That should help to prevent the error.

Offline mystara

  • int
  • **
  • Posts: 79
    • View Profile
Re: OutOfMemoryError
« Reply #8 on: May 05, 2008, 10:24:34 pm »
Awesome, thanks.