On Feb 24, 2026, at 7:43 AM, 'Qingwei Li' via golang-nuts <[email protected]> wrote:

replies are in link:  Re: [go-nuts] Does hand-written move function without runtime support can transfer the ownership of an object entirely?

On Wednesday, January 7, 2026 at 11:29:21 AM UTC+8 Qingwei Li 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].
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/af0d34ff-c78c-4d86-97b6-0e7a347b1975n%40googlegroups.com.

--
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/7A5C036F-9524-4FD7-8A10-797C37104DED%40me.com.

Reply via email to