You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think (and someone should check me if I am wrong)
that get! is borked for WeakKeyDict.
A key part of the functioning of WeakKeyDict, is that when an index is set,
the finalizers are hooked up, such that when that key is garbage collected,
its entry is deleted from the dictionary.
And thus the finalisers are never hooked in.
So the garbage collector does not remove the element from the dict.
The key does get change to WeakRef(nothing) but the value stays in the dict.
This is probably not intended
This is also way get! (unlike setindex) requires you to use WeakRef(k) for the key argument.
(similar for almost every other method. I thing all should take the specified keytype (rather than a WeakRef to it. Just like setindex! )
The text was updated successfully, but these errors were encountered:
oxinabox
changed the title
get! for WeakKeyDict does not add elements to finalizer, so they are not removed on a GC()get! for WeakKeyDict does not add elements to finalizer, so they are not removed on they keys being garbage collected
Nov 23, 2017
I think (and someone should check me if I am wrong)
that
get!
is borked for WeakKeyDict.A key part of the functioning of WeakKeyDict, is that when an index is set,
the finalizers are hooked up, such that when that key is garbage collected,
its entry is deleted from the dictionary.
The following fails in 0.6
Looking at the code: (https://github.com/JuliaLang/yyjulia/blob/0d7248e2ff65bd6886ba3f003bf5aeab929edab5/base/weakkeydict.jl#L109-L110)
get!
on aWeakKeyDict
uses toget!
on aDict
, which in turn usessetindex!(::Dict...)
(well_setindex2
or something),rather than
setindex!(::WeakKeyDict,...)
.And thus the finalisers are never hooked in.
So the garbage collector does not remove the element from the dict.
The key does get change to
WeakRef(nothing)
but the value stays in the dict.This is probably not intended
This is also way
get!
(unlikesetindex
) requires you to useWeakRef(k)
for the key argument.(similar for almost every other method. I thing all should take the specified keytype (rather than a
WeakRef
to it. Just likesetindex!
)The text was updated successfully, but these errors were encountered: