[Mono-list] Embeding Mono. Memory management
Robert Jordan
robertj at gmx.net
Fri Nov 20 09:21:09 EST 2009
Alexander Smirnov wrote:
> yes, I know that t frees them, when no other managed reference is pointing.
>
> But right after I create a string using: MonoString* str=mono_string_new (domain, "some text");
> no managed references point to this string because MonoString* str is not a manged reference.
> So can GC delete "str" right after mono_string_new?
No, it can't. Right after mono_string_new, the pointer is either
on the the current stack or in a processor register.
When a GC collection is started, the stack of all threads and
the processor registers are scanned for reference.
Robert
>
> thanks for your help
>
> 20.11.09, 14:56, "Robert Jordan" <robertj at gmx.net>:
>
>> Alexander Smirnov wrote:
>> > But how GC knows when to free such objects? When it frees such objects?
>>
>> It frees them, when no other managed reference is pointing
>> to them.
>>
>> > Could GC free the object when I still need it?
>> > for example
>> >
>> > void func() {
>> > MonoString* str=mono_string_new (domain, "some text");
>> > /*
>> > could GC free str before "using str", if no, why?
>> > */
>> > // using str
>> > }
>>
>>
>> If you want to use "str" after func () in unwound, then
>> you have to obtain a gchandle for "str". See Mono's
>> mono_gchandle_* functions.
>>
>> Robert
>>
>> _______________________________________________
>> Mono-list maillist - Mono-list at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-list
>>
>>
>
More information about the Mono-list
mailing list