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.
IndexSuggestions & BugsSoftware Bugs › memory leak with OPENGL
Page Index Toggle Pages: 1
memory leak with OPENGL (Read 1431 times)
memory leak with OPENGL
Sep 9th, 2005, 8:27pm
 
Hi!

With this little code down there I have tremendous problems, since its juicing out the memory very constantly, which leads to 0 RAM after a while. If I dont run in OpenGL mode, everything is fine!

Besides that, why is it necessary, to make a new image every frame instead of writing to the pixels array of the same image always (line 'PGraphics3 tmp = new PGraphics3(width,height,null);') This also just occurs with OPENGL

Code:

import processing.opengl.*;
import processing.video.*;

Capture camera;
Silhouette sil;

void setup()
{
colorMode(RGB,255);
size(320 ,240, OPENGL);
camera = new Capture(this, width, height, 20);
sil = new Silhouette();
}

void captureEvent(Capture camera)
{
camera.read();
}

void draw()
{
sil.render();
}

class Silhouette
{
int[] pix;

PImage tmp;
Silhouette()
{
pix = new int[width*height];
}

void setValue(int i, int val)
{
pix[i] = val == 0 ? -100 : pix[i] + 15;
}

void render()
{
this.checkInput(camera.pixels);
tmp = new PImage(width,height);
int px;
for (int i=0; i<width*height; i++)
{
px = constrain(pix[i], 0,255);
tmp.pixels[i] = color(px, px, px) ;
}
image(tmp,0,0);
}

void checkInput(color [] video)
{
int threshold = 127;
float p_bri;

for (int i=0; i<video.length; i++)
{
p_bri = brightness (video[i]);

if (p_bri > threshold) sil.setValue(i,1);
else sil.setValue(i,0);// black
}
}
}


Its obvious that the construction of a PImage every frame cant be good...but if you write the "new PImage" code in the class constructor (where I guess it should be) it doesnt work anymore in OPenGL, just if you make a new one every frame. Which fills the Memory until it dies.
Re: memory leak with OPENGL
Reply #1 - Sep 13th, 2005, 5:04pm
 
PGraphicsGL is not optimized and has some known memory leaking issues. it needs more work for completeness before all that stuff can be straightened out. opengl is basically still alpha-quality code. i've filed a bug so you can actually track the issue here:
http://dev.processing.org/bugs/show_bug.cgi?id=150

and please don't cross-post. is it really too much to wait four days before getting a response to your post? i do this in my free time so you've gotta go easy on me.
Re: memory leak with OPENGL
Reply #2 - Sep 13th, 2005, 5:52pm
 
I apologize for the crossposting.
Yes I got unpatiently.
Yes I have to learn to be more Zen.

I know what you are doing for the project and I am very thankful to that.


I filed the bug as good as I could including the code that produces it. Anyways, I am very much wondering about the 2nd part of the issue: That you always have to construct a new PImage Instance in order to render the image at all - for my understanding, it should be sufficient to construct it once and then re-write the values in the pixels arry. What am I doing wrong?
Re: memory leak with OPENGL
Reply #3 - Sep 14th, 2005, 2:24pm
 
you don't have to keep re-constructing it, which is causing the majority of your problem.

you just have to use loadPixels() whenever you've messed with the pixel data and want it to be re-drawn. if you have more questions about how that works, post the code over in the "programs" section.
Re: memory leak with OPENGL
Reply #4 - Sep 16th, 2005, 5:59pm
 
clarification: you need to use updatePixels() on the PImage that you change, not just call updatePixels().

so in your case you'd only do this once:
tmp = new PImage(...);

and then inside your loop, after messing with tmp.pixels, you call tmp.updatePixels().

(edit: said loadPixels, meant updatePixels...)
Page Index Toggle Pages: 1