[Mono-dev] how-to-protect-object-created-by-mono-object-new-from-gc

xiaozhu niluzhou1984 at foxmail.com
Fri Apr 6 11:56:19 UTC 2018


------------------ Original ------------------
From:  "Bernhard Urban"<beurba at microsoft.com>;
Date:  Fri, Apr 6, 2018 07:01 PM
To:  "xiaozhu"<niluzhou1984 at foxmail.com>;"mono-devel-list"<mono-devel-list at lists.dot.net>;

Subject:  Re: [Mono-dev]how-to-protect-object-created-by-mono-object-new-from-gc

It shouldn't be, because there will be a reference on the native stack or machine registers between step1 and step2 and those areas will be scanned by the garbage collector.


From: Mono-devel-list <mono-devel-list-bounces at lists.dot.net> on behalf of xiaozhu <niluzhou1984 at foxmail.com>
Sent: Friday, April 6, 2018 12:42:48 PM
To: mono-devel-list
Subject: [Mono-dev] how-to-protect-object-created-by-mono-object-new-from-gc


I embed the mono in my game engine.And create managed object by invoke mono_object_new then call mono_gchandle_new to ref the object.


MonoObject* monoObject= mono_object_new()


uint32_t objectHandle = mono_gchandle_new(monoObject,false);

Will monoObject be gabage collected between step1 and step2? If yes how to prevent it.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dot.net/pipermail/mono-devel-list/attachments/20180406/930b1358/attachment.html>

More information about the Mono-devel-list mailing list