[Mono-dev] Embedding Mono + SWIG string return values leads to bad free

Miguel de Icaza miguel at ximian.com
Fri Apr 25 19:16:03 EDT 2008


[resending, email server not working]
On Thu, 2008-04-24 at 18:33 -0400, Miguel de Icaza wrote:
> Hello,
> 
> > The returned string is passed back to the SWIG C# class and used
> > (successfully) and then later the GC tries to collect it and fails.
> > The C# delegate is just something like
> 
> The GC does not collect strings returned from P/Invoke, but it will free
> return values.
> 
> If you are returning strings that are now malloc()ed (and ownership is
> transferred to the caller), you may want to change the P/Invoke
> signature to return an IntPtr, and then use Marshal.PtrToStringAuto
> 


More information about the Mono-devel-list mailing list