3 ms·
> If the only reference to something was passed from Go to Rust, will Go's GC marker find it? No, and rightly so. I would expect https://golang.org/cmd/cgo/#hd
by yencabulator 7y ago
> If the only reference to something was passed from Go to Rust, will Go's GC marker find it?
No, and rightly so. I would expect https://golang.org/cmd/cgo/#hdr-Passing_pointers https://golang.org/cmd/cgo/#hdr-Passing_pointers to apply just as much here as with CGo (the criteria is "foreign allocator", not CGo).
- Animats 7y agoWhich is a problem here, because the OP is calling Rust from Go using the Go calling sequence. So Go's checking doesn't know it's calling non-Go code. There's a defined way to call C from Go, but the OP is not using that interface.
- yencabulator 7y agoIt's fine as long as you don't store Go pointers in non-Go memory. If the local variable is the last reference to the thing, https://golang.org/pkg/runtime/#KeepAlive https://golang.org/pkg/runtime/#KeepAlive makes sure the Go side doesn't drop it before the call is complete.