On Tue, Jan 21, 2025 at 6:10 PM John <
johns...@gmail.com> wrote:
>
> Curious if the new runtime.Cleanup() would allow auto sync.Pool.Put() for a variable. I'm not sure from the documentation if this would work or would cause some type of issue (the variable was on its way to collection and then gets put in a pool. I assume it would stop collection?). The guarantees for running it seem to be better than Finalizer for this kind of thing (its working for file closures, so I'm guessing this will eventually happen), but still not sure how much better.
It should be fine to use runtime.AddCleanup to add something to a
sync.Pool. That said, remember that runtime.AddCleanup is not called
with the pointer that is being freed. It is called on a different
pointer, that is presumably associated in some way.
Ian