that's the problem, i use c just like an channel, the value final send to 
other language. i know i can make an call back function in c and then 
release that memory in c code.
 regrettably, this will take many time and i don;t have so much.
however ,thx

在2020年11月18日星期三 UTC+8 上午10:43:20<Ian Lance Taylor> 写道:

> On Tue, Nov 17, 2020 at 6:38 PM 杜仲 <whe...@gmail.com> wrote:
> >
> > my go version is 1.13.
> > i used cgo.cstring in my func, and the func will return cstring.
> > i don't know when c complete work about the cstring memory.
> > if i used defer c.free to release the cstring memory, the cstring val 
> will change and return a unexpected value, especially at often apply memory 
> on low memory environment.
> > now i use a funccollect the pointer and release after 1 hour or later.
> > is there any other way to solve?
>
> A string allocated with C.CString is allocated using the C malloc
> function. It sounds like you are passing that string to C, in which
> case it becomes the responsibility of the C code to free the string.
> C code has to be aware of memory use and has to free memory when it is
> no longer needed. If your C code does not track memory properly, that
> is unfortunate, but there is nothing you can do to fix it safely on
> the Go side.
>
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ef1f610d-650e-43dc-8a98-e2d120aae9c5n%40googlegroups.com.

Reply via email to