# PImage garbage not being properly collected

**URL:** https://discourse.processing.org/t/pimage-garbage-not-being-properly-collected/12252
**Category:** Coding Questions
**Created:** [June 23, 2019, 6:00pm UTC](https://discourse.processing.org/t/pimage-garbage-not-being-properly-collected/12252 "2019-06-23T18:00:14Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [June 24, 2019, 12:55am UTC](https://discourse.processing.org/t/pimage-garbage-not-being-properly-collected/12252/4 "2019-06-24T00:55:24Z")

</div>

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:

```auto
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:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7a6381c87d91428231db13d5c5715861455e9a86.png)

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

```auto
  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!

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/363fea34dba2eb88324f048554bb1d48d0bb4745.png)

🙂

---

_[View the full topic](https://discourse.processing.org/t/pimage-garbage-not-being-properly-collected/12252)._
