On Tue, Nov 17, 2020 at 6:38 PM 杜仲 <whee...@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/CAOyqgcUJm5eReHtxOxaTCsCctfv1JSab5hWwyPBoUca2NnEm-w%40mail.gmail.com.

Reply via email to