We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › difference jar and exe in memory or garbage c...
Page Index Toggle Pages: 1
difference jar and exe in memory or garbage c... (Read 399 times)
difference jar and exe in memory or garbage c...
Feb 15th, 2008, 12:55pm
 
Is there some difference I should know about in memory or garbage collection between running something in a browser or as an exe (or directly from p55)?

For a few days I've been trying to find a memory leak but I've been unable to find it. This is a rebuild of something I made two years ago (still far from finished):

http://www.sjeiti.com/test/attractors2/

After a few renders the viewport rotation (left mouse drag), panning (right mouse drag) and changing constants (those sliders) slow down extremely. While other functions like rollovers or the iterations slider keep running smoothly.

To calculate the points I instantiate a small vector class a few thousand to million times. It's just that these are local variables and should be cleaned up. That must be the bottleneck, but pushing the re-iterate button when the applet is slowed down also works smoothly. So it's puzzling.
I'm pretty sure it has nothing to do with images because I get the same problem if I don't render but just change the sliders for ten minutes or so (it just takes a little longer).

Simply calling the garbage collector after and before each render has no effect at al.
Also, emptying the cache and reloading doesn't help. Only after closing all browser instances will it run smoothly again. I'm beginning to think this is really a java bug.

Strangely, the exe and running from processing itself work perfectly. I have another computer on which it's been rendering a movie for 30+ hours with no loss in framerate (rendering movies is not visible in the online version).

Anyway... I hope somebody can shed some light on this. It would be a pity to abandon the online version of this thing.
Re: difference jar and exe in memory or garbage c.
Reply #1 - Feb 15th, 2008, 5:39pm
 
...thought I had something... but it's a false alarm Sad

-update-

Well it does seem to help a bit, so here's what:
Don't trust the garbage collector! I had a simple vector class instance that was returned each iteration (x-million times). It was a local variable but appearantly it did not get garbage collected. I had to explicitly set it's variable to null after usage. That helped a bit.

Then there is also this:
http://forum.java.sun.com/thread.jspa?threadID=5138898&tstart=180
Re: difference jar and exe in memory or garbage c.
Reply #2 - Feb 16th, 2008, 12:01am
 
m...

I probably shouldn't be touching this, but the even -better- method is to "reuse" basic classes like Vector and Point3D...

//Everyframe, I generate thousands of Vector3D objects:
setup(){
 ...
 myVectorPool = new ArrayList();
}
ArrayList myVectorPool;
int usedVectorsThisFrame = 0;
draw(){
   usedVectorsThisFrame = 0; //IMPORTANT
   ...
   for(...){
       Vector using = getPoolVector();
       using.init(x,y,z); // substituted for "new vector3D"
   }
}
public Vector3D getPoolVector(){
   if (myVectorPool.size()==usedVectorsThisFrame){
         Vector3D ret = new Vector3D();
         myVectorPool.add(ret);
         usedVectorsThisFrame++;
         return ret;
   }      
  return myVectorPool.get(usedVectorsThisFrame++);
}

? I think this is a fine solution. Myself, I'd write it with a linkedlist for the slight optimization... but this is really how to avoid relying on the garbage collector for animations.
Re: difference jar and exe in memory or garbage c.
Reply #3 - Feb 18th, 2008, 11:06am
 
Good suggestion... I'll do that.
I still find it strange that normal garbage collection doesn't work. Is this a bug or a strange side effect?
Page Index Toggle Pages: 1