memory leak from using buffer = createGraphics(iw, ih, JAVA2D);
in
Programming Questions
•
1 year ago
I am animating some images and using a buffer so that i can scale up the output without having to scale up all of the components of every frame.
When not using the buffer the script will run indefinitely without any problems, however when I use the buffer it runs out of memory after 10 seconds or so, even when it is just repeating the same 20 frames.
I used a similar approach to the one outlined here:
http://wiki.processing.org/w/Draw_to_off-screen_buffer
the relevant bits of the script are as follows:
void draw()
{
// tint(255,85-85*(frame3+samplesize/2-pos)/samplesize);
updatebuf();
incframes();
loopanim();
updatepos();
drawtoscreen();
}
{
// tint(255,85-85*(frame3+samplesize/2-pos)/samplesize);
updatebuf();
incframes();
loopanim();
updatepos();
drawtoscreen();
}
void updatebuf()
{
buf.beginDraw();
buf.background(0);
buf.tint(255,235,25,255);
buf.image(img[frame[0]],0,0);
buf.tint(178,18,77,204);
buf.image(img[frame[1]],0,0);
buf.tint(255,0,94,153);
buf.image(img[frame[2]],0,0);
buf.tint(20,169,204,102);
buf.image(img[frame[3]],0,0);
buf.tint(9,146,178,51);
buf.image(img[frame[4]],0,0);
buf.endDraw();
}
{
buf.beginDraw();
buf.background(0);
buf.tint(255,235,25,255);
buf.image(img[frame[0]],0,0);
buf.tint(178,18,77,204);
buf.image(img[frame[1]],0,0);
buf.tint(255,0,94,153);
buf.image(img[frame[2]],0,0);
buf.tint(20,169,204,102);
buf.image(img[frame[3]],0,0);
buf.tint(9,146,178,51);
buf.image(img[frame[4]],0,0);
buf.endDraw();
}
void drawtoscreen()
{
background(0);
bimage = buf.get(0, 0, buf.width, buf.height);
tint(255,255);
image(bimage,0,0,iw*2,ih*2);
}
{
background(0);
bimage = buf.get(0, 0, buf.width, buf.height);
tint(255,255);
image(bimage,0,0,iw*2,ih*2);
}
I'm not sure why it's using so much memory, any ideas?
1