This site requires JavaScript, please enable it in your browser!
Greenfoot back
Montoya
Montoya wrote ...

2011/9/8

Memory Leak in GreenfootSound?

Montoya Montoya

2011/9/8

#
I've been working with dynamically changing volume based on the distance between two characters: double dist = Math.sqrt((Math.pow((MazeWorld.Play1.xPos-xPos),2)+Math.pow((MazeWorld.Play1.yPos-yPos),2)))/Math.sqrt(2*Math.pow(MazeWorld.size,2)); Open.setVolume((int)(100-(dist*60))); Close.setVolume((int)(100-(dist*80))); and fairly quickly run out of memory. Is this a known problem, or am I doing something wrong?
Builderboy2005 Builderboy2005

2011/9/8

#
This happens to me as well in my Nightmare scenario, although I am not sure whether it is because of sound or not. Every so many compiles I have to restart Greenfoot, or else Java runs out of memory. There was a new update though so let's see if it fixes it ^^
bourne bourne

2011/9/8

#
Yeah I had similar problems when compiling a large project just a couple times.
davmac davmac

2011/9/8

#
There was a resource leak with setVolume(), but this should no longer happen in Greenfoot 2.1.1.
Builderboy2005 Builderboy2005

2011/9/9

#
Ah, that makes sense. Pretty much every sound in Nightmare calls SetVolume every frame in Nightmare :P
davmac davmac

2011/9/12

#
Does the new version seem to help, Builderboy2005?
Builderboy2005 Builderboy2005

2011/9/12

#
I still have to recompile Nightmare every now and then :/ Is there anything I could be doing that isn't letting resources be released?
davmac davmac

2011/9/13

#
Hmmmm. Nothing I can think of. You could try editing the greenfoot.defs file (in the "lib" folder inside the Greenfoot folder) and changing the "bluej.vm.args" setting - try removing the "-Xincgc" part. The "-Xincgc" specifies to use the incremental garbage collector, which is designed to reduce the pauses due to garbage collection; however, I have noticed that it sometimes fails to reclaim all memory. The other thing you could do is give more memory to Greenfoot, by adding "-Xmx512m" (for 512 megabytes for example) to the same setting. eg: bluej.vm.args=-Xmx512m -Dapple.awt.graphics.UseQuartz=true (You can remove the "-Dapple..." setting also, if you're not on a Mac).
Builderboy2005 Builderboy2005

2011/9/13

#
Would changing the garbage collection settings impact the exported applet as well? Pauses due to garbage collection are indeed no good D:
davmac davmac

2011/9/13

#
It won't change the exported applet, as that runs in the Java plugin which just uses the default VM settings (meaning: the standard garbage collector). Also, you'll probably find it doesn't make too much difference anyway, especially with Java 7. The pauses are mostly unnoticeable.
Builderboy2005 Builderboy2005

2011/9/13

#
ah, in that case I'll definitely implement the change :D thanks a bunch!
You need to login to post a reply.