Thanks your reply, the point is that I do not know where the C code is completely done it. So, I do not release the C.CString currently, but I worry if I have not released the C.CString, whether the Go code will crash somewhere.
在 2017年8月15日星期二 UTC+8下午12:35:05,Ian Lance Taylor写道: > > On Mon, Aug 14, 2017 at 7:21 PM, <jianzh...@gmail.com <javascript:>> > 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.