Hi,

Regarding this thread:
https://forum.golangbridge.org/t/curious-about-runtime-keepalive-usage/3530

And also the original problem example from Russ:
https://github.com/golang/go/issues/15277#issuecomment-221768072

... I just wanted to get clarification on this situation:

func f(ptr *Object) {
    C.doStuff(ptr.c_ptr)
}
func main() {
    f(NewObject())
}

​

If someone were to create a transient object as an argument to a function
call (keeping no reference to it), and then the function uses a field that
is a C pointer to call into a C function, would it be possible for the
wrapping Go object to get collected and trigger a finalizer which could
cause the C memory to get freed during that C calls?

And another variation, just in case this makes a difference:

func f(ptr *Object) {
    c_ptr := ptr.c_ptr
    C.doStuff(c_ptr)
    C.doStuff2(c_ptr)
}

​
Basically, I wasn't sure whether the ptr object would be considered live or
not, based on whether the caller hangs onto it or not.

Justin

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to