PImage garbage not being properly collected

Another exploration with less memory:

  1. In Processing “Preferences” I set maximum available memory to 1024 MB.
  2. keyPressed() modified so it would do the same as your midnight “reset” for testing.

It crashed on a key press:

void keyPressed() {
  if (key == 'p') saveFrame("save.png"); 
  if (key == 'r') {
    frameCount = -1;
    freeStuffUp();
    thread("init"); \\ Added this!
  }

You can see where it crashed at end of image:

Same settings as above but with the addition of System.gc() at end of draw():

  println(mouseX, ' ', mouseY);
  //println(frameRate);

  System.gc();
}

And voila! It would only crash if I pressed it during a peak cycle of the “used heap” otherwise seemed to run fine; I would use more memory!

:slight_smile:

2 Likes