PImage memory leak
in
Programming Questions
•
7 months ago
Hello
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; // 27500 27.5 sec
- int whaitTime = 1000; // 5000 5 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
- time = millis(); // reset the time
- }
- }
-
- void stop() {
- // stop the minim object
- minim.stop();
- super.stop();
- }
1