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
may schedule both cleanups. There is no guarantee as to which cleanup