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 am currently using a workaround where I nilify the Cond in a struct when the associated struct is not pooled. I am using a custom pool, so I don't know if the above would be problematic for the GC when used with a sync.Pool that is purged.
What did you expect to see?
Struct should have been GC'ed
What did you see instead?
The opposite.
The text was updated successfully, but these errors were encountered:
If a cyclic structure includes a block with a finalizer, that cycle is not guaranteed to be garbage collected and the finalizer is not guaranteed to run, because there is no ordering that respects the dependencies.
I think that's what you are running into. You have a 2-object cycle with a finalizer on one of the objects. That finalizer can never get run.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Reproduces on https://go.dev/play/p/5bfwPnkYyY3
What operating system and processor architecture are you using (
go env
)?Have tried on darwin/amd64, linux/mips32, and whatever os/arch runs on Go Playground.
What did you do?
sync.Mutex
and a*sync.Cond
sync.Cond
, using a pointer to the mutex in the struct.runtime.GC()
, sleep... no finalizer is called.sync.Cond
or by settingx.cond = nil
, the finalizer is called.See the playgound for a sample: https://go.dev/play/p/5bfwPnkYyY3
I am currently using a workaround where I nilify the Cond in a struct when the associated struct is not pooled. I am using a custom pool, so I don't know if the above would be problematic for the GC when used with a
sync.Pool
that is purged.What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: