I have an out of memory issue I wasn't able to solve.
There are several threads about memory leaks but non of them provided a solution so far.
I want to make a slide show with more then 100 images where only 3 are in memory and I load the next one when ready.
Unfortunately the memory keeps filling until the app crashes.
My settings: Windows 7 Professional, Processing 2.0b8, Java 7 Update 17
or: OSX 10.8.2, Processing 2.0b8
I would appreciate some help.
*UPDATE
This is strange. I tried to preload all the images in setup.
I was analyzing how much memory my sketch uses with Runtime.getRuntime().totalMemory());
I get 937099264 which will stay the same. But my system monitor tells me that the sketch is increasing its memory use and it crashes with a OOM after some time.
It starts at about 800 MB and crashes at 1.05 GB.
The increased the memory in the Processing preference to 1000 MB.
// import the audio library and create the player object
import ddf.minim.*;
Minim minim;
AudioPlayer player;
PImage imgA, imgB, imgC; // A: backgrund, B: fade in, C: next to load
int filesTotal = 116;// 116 in total
int filesCounter = 1;// the next file to load
int filesLoaded = 0;// how many files were loaded
float picAlpha;// the alpha form the fading image
int transTime = 1000;// 2750027.5 sec
int whaitTime = 1000;// 50005 sec
int time = 0;// time when the last fade war finished
int timer = 0;// elapsed time since the last fade started
void setup() {
size(1920, 1080);
noCursor();// hide the cursor
blendMode(BLEND);// set the blend mode
// open audio player and load the file
minim = new Minim(this);
player = minim.loadFile("sndTrack.wav");
// load the first three images
imgA = loadImage("001d.jpg");
imgB = loadImage("002d.jpg");
imgC = loadImage("003d.jpg");
filesCounter = 4;// the next file to load
time = millis()+whaitTime;// reset the time
}
void draw() {
timer = millis()-time;// update elapsed time
picAlpha = map(timer, 0, transTime, 0, 255);// calculate the alpha based on elapsed time
background(0);// clear the scene
tint(255, 255);// 0 alpha for the background image
image(imgA, 420, 0);// draw background image
tint(255, picAlpha);// set alpha for the fade image
image(imgB, 420, 0);// draw fade image
if (timer > transTime + whaitTime) {// switch the images
// switch out the images
imgA = imgB;
imgB = imgC;
imgC = requestImage(nf(filesCounter, 3)+"d.jpg");
filesCounter++;// increase the file counter
if(filesCounter == filesTotal) filesCounter = 1; // restart from the beginning when all files are drawn
I was just gathering some code snippets for a script that will watch if a certain application is running and will automatically restart it in case of a crash or if the user is quitting it.
This might me useful if you show a processing app in an exhibition.
Of course there should be no bugs and it shouldn't crash, but you never know for sure ;-)