Thank you for the super-fast and authoritative response! OK, I will work on an alternative solution for cleaning up hierarchies in bottom-up order and will report back here if/when I find a good solution.
Regards, Tom On Wednesday, February 19, 2025 at 10:20:22 PM UTC+1 Ian Lance Taylor wrote: > On Wed, Feb 19, 2025 at 1:12 PM twp...@gmail.com <twp...@gmail.com> wrote: > > > > The documentation for runtime.AddCleanup says: > > > > > There is no specified order in which cleanups will run. > > > > Given the following types: > > > > type Parent struct { > > parentResource int > > } > > > > type Child struct { > > parent *Parent > > childResource int > > } > > > > and the following code: > > > > parentResource := 0 > > parent := &Parent{ > > parentResource: parentResource, > > } > > runtime.AddCleanup(parent, func (int) {}, parentResource) > > childResource := 1 > > child := &Child{ > > parent: parent, > > childResource: childResource > > } > > runtime.AddCleanup(child, func(int) {}, childResource) > > > > is it guaranteed that the cleanup for childResource will run before the > cleanup for parentResource? > > No. There is no specified order in which cleanups will run. > > The fact that child points to parent doesn't really matter here. They > can both be collected as garbage in the same GC pass, and that GC pass > may schedule both cleanups. There is no guarantee as to which cleanup > will be scheduler first or which will run first. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/7ecad685-5ca6-4db6-b09d-bdce8f60d7can%40googlegroups.com.