clear an array of PImages / memory question
in
Programming Questions
•
2 years ago
hallo,
i have, inside of FOR-loops, arrays of PImages which are filled with different images from disk everytime the loop is executed. but i have the feeling that the loaded data from the past runs of the loop are still in the memory, since the swap usage and swap space of my machine is growing more and more while the sketch s running. i need the PImages only for the time of one run of the loop, then i need the next set of images in the array of PImages. is there a way to clear the image data from the memory? i have already tried to set the PImage array =null at the loop's end; and also to set each of its slots/elements to null, but it didn't reduce the swap amount of memory.
i only put in the relevant part of the sketch. does anyone have a hint?
thanks in advance and best regards, florian.
- [...]
- for(int n=0; n<expGroups; n++){
- expfr_array=new PImage[expImgAmnt];
- for(int i=0; i<expfr_array.length; i++){
- expfr_array[i]=createImage(useAmount*stripe, imageh+int(ratio*(maxOS-minOS)), RGB);
- };
- for (int m=0; m<srcGroups; m++){
- srcfr_array = new PImage[srcImgAmnt];
- for(int i=0; i<srcfr_array.length; i++){
- srcfr_array[i]=loadImage(srcpath+"DSC_" + str(7666+int(i)+(m*srcImgAmnt)) + ".JPG");
- println("loading source " + (7666+i+(m*srcImgAmnt)));
- };
- for(int j=0; j<expfr_array.length; j++){
- expfr_array[j].loadPixels();
- print("copy: ");
- for(int i=0; i<srcfr_array.length; i++){
- srcfr_array[i].loadPixels();
- [... bla bla bla ... ]
- };
- print(j + " ");
- expfr_array[j].updatePixels();
- };
- for(int i=0; i<srcfr_array.length; i++){
- srcfr_array[i]=null;
- };
- srcfr_array = null;
- println();
- };
- for(int j=0; j<expfr_array.length; j++){
- image(expfr_array[j], 0, 0, width, height);
- saveFrame(outpath+"frame-" + nf(1+(j+(n*expImgAmnt)), 4) + ".JPG");
- println("target " + (j+(n*expImgAmnt)+1) + " saved");
- };
- expfr_array=null;
- };
- };
- [...]
1