[Mono-list] lifetime of MonoMethod in mono embedding

Robert Jordan robertj at gmx.net
Wed Nov 18 14:47:29 EST 2009


ptr2009 wrote:
> hey all
> 
>    It seems like when using mono_object_new in an embedded application you
> are supposed to use mono_gchandle_new to store a handle to the object so
> that it is not garbage collected when you reference it again. 
> 
>   1) what is appropriate value of pinned gboolean to be passed to
> mono_gchandle_new . Does it always need to be passed as TRUE ?

TRUE is only needed if the object may not be moved after
you've got a handle for it. With the current GC it doesn't
matter, but this may change in the future.

>   2) I also have a call a method on this object handle periodically.  Is it
> safe to store a pointer to MonoMethod that is returned from
> mono_class_get_method_from_name in your native code. Is MonoMethod* pointer
> effected by the garbage collector.  Is there an equivalent of
> mono_gchandle_new for methods ?
> 

MonoMethod* is an unmanaged structure. As such it's not GCed and
there is no "mono_gchandle_new" for it. In general, if an API
needs some kind of freeing, it will be documented. MonoMethods
do not need to be freed.

Robert



More information about the Mono-list mailing list