# How to garbage collect a DistributedArray for sure?

**URL:** <https://discourse.julialang.org/t/how-to-garbage-collect-a-distributedarray-for-sure/34174>\
**Category:** General Usage\
**Created:** [February 4, 2020, 4:28pm UTC](https://discourse.julialang.org/t/how-to-garbage-collect-a-distributedarray-for-sure/34174 "2020-02-04T16:28:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [February 4, 2020, 4:28pm UTC](https://discourse.julialang.org/t/how-to-garbage-collect-a-distributedarray-for-sure/34174/1 "2020-02-04T16:28:52Z")

</div>

Let’s say I create a DistributedArray but then reassign the variable to a new one:

```julia
using Distributed
addprocs(1)

using DistributedArrays, LinearAlgebra

da = DArray([@spawnat wid LinearAlgebra.ones(div(1024^3, 8)) for wid in procs()])
# Total memory size should be 2GB

da = DArray([@spawnat wid LinearAlgebra.ones(div(1024^3, 8)) for wid in procs()])

```

Even if I run `@everywhere GC.gc()` a few times, the first array **is still not garbage collected**.  
How do I deallocate the first array **for sure?**

What if a DistributedArray is contained as a field inside some `struct`: how do I make sure that this array is deallocated when the `struct` is garbage collected?
