https://github.com/golang/go/issues/13347#issuecomment-158568326 seems to suggest runtime.KeepAlive() is not needed but it does not seem definitive.
If there is a function such as the one below (from https://gitlab.com/YottaDB/Lang/YDBGo/blob/47f5960d03b2c00ae33222ec1d3bdc60a98226c1/buffer_t.go#L151) in an application that has Go structures with pointers to C structures and which uses Finalizers to free the C structures when the Go structures are collected, is the runtime.KeepAlive(ibuft) required to guarantee that ibuft is never collected by the Go garbage collector until after the return from Free()? // Calls C.free on any C memory owned by this internalBuffer func (ibuft *internalBufferT) Free() { printEntry("internalBufferT.Free()") if nil == ibuft { return } cbuftptr := ibuft.cbuft if nil != cbuftptr { // ydb_buffer_t block exists - free its buffer first if it exists if nil != cbuftptr.buf_addr { C.free(unsafe.Pointer(cbuftptr.buf_addr)) } C.free(unsafe.Pointer(cbuftptr)) ibuft.cbuft = nil } runtime.KeepAlive(ibuft) } Thank you very much. Regards – Bhaskar -- 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/d7324145-f422-4453-8524-930d2882aa16%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.