# Garbage collection

**URL:** <https://discourse.processing.org/t/garbage-collection/22537>\
**Category:** Beginners\
**Created:** [July 10, 2020, 4:37pm UTC](https://discourse.processing.org/t/garbage-collection/22537 "2020-07-10T16:37:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [July 10, 2020, 4:37pm UTC](https://discourse.processing.org/t/garbage-collection/22537/1 "2020-07-10T16:37:09Z")

</div>

I’m handling a big arrayList in my program to create a terrain, however I want the users to be able to load their own files, so that anything you can retrieve saves or simply create terrains using a txt file. Issue is once the file is read, I ask the program to clear its contents and re-initialise the variables using a method stored in the grid class. Issue is the new grid is in fact created however space isn’t cleared in memory and memory usage goes up.

Having googled this problem I see that there is a function call to request this from Java vm but its not guaranteed, so I just wanted to see if there was any alternatives for what I’m trying to achieve.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 10, 2020, 4:44pm UTC](https://discourse.processing.org/t/garbage-collection/22537/2 "2020-07-10T16:44:52Z")

</div>

> [@paulgoux](#):
>
> … but it’s not guaranteed,

[Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.html#gc()](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.html#gc())

> , the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.
