# WeakKeyDict(x=\>x) holds on to memory

**URL:** <https://discourse.julialang.org/t/weakkeydict-x-x-holds-on-to-memory/34187>\
**Category:** General Usage\
**Created:** [February 4, 2020, 9:31pm UTC](https://discourse.julialang.org/t/weakkeydict-x-x-holds-on-to-memory/34187 "2020-02-04T21:31:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [February 4, 2020, 9:31pm UTC](https://discourse.julialang.org/t/weakkeydict-x-x-holds-on-to-memory/34187/1 "2020-02-04T21:31:03Z")

</div>

```julia
julia> wk = let x = Ref{Any}(nothing)
           WeakKeyDict(x=>x)
       end
WeakKeyDict{Base.RefValue{Any},Base.RefValue{Any}} with 1 entry:
  RefValue{Any}(nothing) => RefValue{Any}(nothing)

julia> GC.gc()

julia> GC.gc()

julia> GC.gc()

julia> wk
WeakKeyDict{Base.RefValue{Any},Base.RefValue{Any}} with 1 entry:
  RefValue{Any}(nothing) => RefValue{Any}(nothing)

```

I guess… that’s… correct? Does anyone have an explanation for this behaviour? The doc string does not help:

> WeakKeyDict() constructs a hash table where the keys are weak references to objects which may be garbage collected even when referenced in a hash table.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [February 4, 2020, 9:39pm UTC](https://discourse.julialang.org/t/weakkeydict-x-x-holds-on-to-memory/34187/2 "2020-02-04T21:39:54Z")

</div>

Only the keys are weak references but not the values. Compare to:

```julia
julia> wk = let x = Ref{Any}(nothing)
                  WeakKeyDict(x=>1)
              end
WeakKeyDict{Base.RefValue{Any},Int64} with 0 entries

```
