Also, there is no “ownership by routine” - the only time this might come into play is a system with "thread local" storage - which even then doesn’t isolate the object as it can still be shared with other threads to “escape” ownership.
There is no concept of ownership in a GC system - that is the point - the runtime manages all object lifecycles for you - if an object is reachable it is “alive” and if not, it will be garbage collected. Note, this is orthogonal to concurrency issues involved when sharing objects across Go routines. Also, you can perform manual memory management in Go - but it is rarely needed unless interfacing with existing non-Go libraries. > On Jan 6, 2026, at 9:29 PM, Qingwei Li <[email protected]> wrote: > > Take the following program as an example. > > ```go > c, err := getFtpConnection() > if err != nil { > return nil, err > } > go func(c2 *ftp.ServerConn) { > c2.List() > }(c) > // c will not be used later > ``` > > let's add `move` function. > > ```go > func move[T any, PT *T](pp *PT) (res PT) { > res = *pp > *pp = nil > return > } > > // Goroutine G1 > c, err := getFtpConnection() > if err != nil { > return nil, err > } > go func(c2 *ftp.ServerConn) { // Goroutine G2 > c2.List() > }(move(&c)) > // c will not be used later > ``` > > Would this `move` without runtime support make GC unable to reach the object > pointed by `c` scanning from the stack of goroutine G? If it does, the > ownership of object is entirely moved to goroutine G2. With the ownership > transfering, freegc for `c2` in the end of goroutine G2 is feasible in > cross-goroutine reference case. > > > -- > 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 [email protected] > <mailto:[email protected]>. > To view this discussion visit > https://groups.google.com/d/msgid/golang-nuts/97151e98-d453-4ca6-9454-7abe8a27a6abn%40googlegroups.com > > <https://groups.google.com/d/msgid/golang-nuts/97151e98-d453-4ca6-9454-7abe8a27a6abn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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 [email protected]. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/68E436AF-2DA3-4B85-B675-99FF0D5A9AD0%40me.com.
