# Clearing up memory

**URL:** <https://discourse.julialang.org/t/clearing-up-memory/28670>\
**Category:** New to Julia\
**Created:** [September 11, 2019, 10:23pm UTC](https://discourse.julialang.org/t/clearing-up-memory/28670 "2019-09-11T22:23:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [September 11, 2019, 10:23pm UTC](https://discourse.julialang.org/t/clearing-up-memory/28670/1 "2019-09-11T22:23:30Z")

</div>

Hi, I had a question about clearing up memory by removing temporary variables that we have used. For example, if I create a huge matrix

`julia> A = rand(100000,10000);`

the memory usage on my RAM visibly increases. If I reassign `A` to be a `Float64`, as in

`julia> A = 2.0;`

it still does not clear up the memory. It would be useful if I could get rid of arrays or variables that are needed temporarily in the middle of big computations.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 11, 2019, 10:27pm UTC](https://discourse.julialang.org/t/clearing-up-memory/28670/2 "2019-09-11T22:27:19Z")

</div>

2 things. First, you should almost never be reassigning the types of variables. second, you can manually run a GC run with `GC.gc()`. Note you should not do this frequently.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [September 12, 2019, 12:40am UTC](https://discourse.julialang.org/t/clearing-up-memory/28670/3 "2019-09-12T00:40:32Z")

</div>

but when you actually need that RAM, GC should kick in. There’s no point clearing unused RAM too eagerly.

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [September 12, 2019, 2:12pm UTC](https://discourse.julialang.org/t/clearing-up-memory/28670/4 "2019-09-12T14:12:19Z")

</div>

Thank you for pointing me to the concept of “Garbage Collection”. I will learn more about it.

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [September 12, 2019, 2:12pm UTC](https://discourse.julialang.org/t/clearing-up-memory/28670/5 "2019-09-12T14:12:41Z")

</div>

Thank you. I will learn more about “Garbage Collection”.
