On Wed, Aug 21, 2019 at 5:55 AM zct <tangzhongch...@bytedance.com> wrote: > > I recently had a goroutine leak problem, the code i reduced is like this: > https://play.golang.org/p/YW4hWoZZ7CD. > > The program is long-running and the finalizer is not called > > The RoomObj is deleted from map, why was it not released? Is it refereed by > the asyncChan object? > > I don't understand here, can somebody explain the reason
Your finalizer itself is keeping the value alive. runtime.SetFinalizer(a, func(r *RoomTest) { fmt.Println("SetFinalizer") close(a.asyncChan.a) }) You need to write the finalizer function to refer to r, not a. The reference to a in the finalizer function ensures that a is always live. 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 on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWwYTGGULQnhBeG804Om33PoppxsVFC%2B8ZuAqL78uXfOw%40mail.gmail.com.