[Gtk-sharp-list] Upcoming problems.

Paolo Molaro lupus@ximian.com
Tue, 27 May 2003 19:10:06 +0200


On 05/26/03 Miguel de Icaza wrote:
> 	[Dllimport ("")]
> 	extern static string method ();
> 
>    Carry an explicit invocation to 'free' on the result value returned
> by the unmanaged code.  This is done to avoid leaks. 

Note: the implicit invocation is _not_ to free(), but to CoTaskFreeMem
or whatever the function is called. Of course, on unixes we'll call
free() instead. Note: the jit currently does this incorrectly on both
platforms, because it uses g_free().
So, while in the case of a const char* return using
Marshal.PtrToStringAuto _may_ be fine (Marshal.PtrToStringAnsi is
probably better, because it always deals with 8-bit data, the Auto
variant may use utf-16 on windows), something along the same lines needs
to be done also for simple char* return types, since the memory is
allocated by g_malloc() and hence must be freed by g_free().

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better