Of course you can pass Nim strings to C functions, but you have to ensure that 
the Nim string lives as long as it is used by the C lib. Most C libs seems to 
make a copy of the passed string when the lib uses the string still when the 
function has terminated. If the C function does not make a copy but continues 
to use that string, then you would have to GC_ref it or to pass a copy that you 
allocate yourself with low level functions like alloc().

Maybe copy your Nim string to a Nim Cstring and call GC_ref() on the Nim 
cstring, I would assume that it may work. Modern Nim strings are value objects, 
so we can not call GC_Ref on them, but for CStrings it may work still. 
Otherwise search for procs related to alloc() or create() maybe.

Note that it is not a ARC problem, the default GC just delays deallocation, so 
that such problems can be hidden for long time.

The real problem is reliable releasing such copied string. Who does release it, 
the C lib or your code? 

Reply via email to