3 ms·
I don't understand why SetFinalizer+resurrected could prevent a memory block which will be collected from being collected. Update: never mind, I re-read the do
by tapirl 6y ago
I don't understand why SetFinalizer+resurrected could prevent a memory block which will be collected from being collected.
Update: never mind, I re-read the docs of SetFinalizer to get the explanation:
SetFinalizer sets the finalizer associated with obj to the provided
finalizer function. When the garbage collector finds an unreachable block
with an associated finalizer, it clears the association and runs
finalizer(obj) in a separate goroutine. This makes obj reachable again,
but now without an associated finalizer. Assuming that SetFinalizer
is not called again, the next time the garbage collector sees
that obj is unreachable, it will free obj.