On Mon, Aug 14, 2017 at 7:21 PM, <jianzhang...@gmail.com> wrote: > > I need to call a C function with CGO, but if I release the memory of the > C.CString, then the related C function returns errors. > I think the C function based on the string slice(char**) created by the > C.CString all the way. > So, if I do not release the memory created by the C.CString of CGO all the > way, will there be any problem? > Will this memory be automatically reclaimed by the garbage collection > mechanism of go? > And is there any better way to do this?
Memory allocated using C.CString will not be freed by the Go garbage collector. You must free it yourself by calling C.free. Of course, you should only free it when the C code is completely done it, just as with any other C pointer. Ian -- 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.