Any methods to let a custom function automatically run by GC after each garbage collection operation?

I want to remove some WeakRef related resources, e.g.

struct Blah
    dummy::String
end
a = Blah("abc")
b = Dict()
b["a"] = WeakRef(a)

function do_cleaning()
    for (k, v) in b
        if v.value == nothing
            delete!(b, k)
        end
    end
end

a = nothing
GC.gc()
show(b)       # b["a"]=>Blah()
do_cleaning() # Make this automatic after a GC round!
show(b)       # empty

Is it possible?

just make your own .gc function to do both

I mean I want it to run even after automatic gc operations run by RT/VM. -

You probably want to use the API specified in this Julep (see post_gc callback): https://github.com/JuliaLang/Juleps/blob/master/GcExtensions.md

PR was merged into Julia here: https://github.com/JuliaLang/julia/pull/28368