It’s not an issue with
julia> let ret = Ref(0)
global f = ret
julia> f = 0
I believe the issue is approximately that Julia doesn’t GC methods, merely updates the method table (ref 11695, but that’s only talking about object code specifically). You may have noticed that the finalizer does run when you cleanly exit Julia.
However, this doesn’t quite make sense in a few test cases I tried because the AST only appears to be storing a literal.
(by the way:
finalizer should not cause a task switch, such as by performing I/O, but this was not documented – see https://github.com/JuliaLang/julia/pull/25141 for workarounds)