[Development] Qt 5.9's new garbage collector documentation? + root_ptr
Phil Bouchard
philippeb8 at gmail.com
Sun Jul 16 05:01:40 CEST 2017
On 07/15/2017 07:49 PM, Phil Bouchard wrote:
> On 07/15/2017 07:21 PM, Tim Blechmann wrote:
>>>>>> fwiw, to get this thread back to the main topic, i still fail to see
>>>>>> how
>>>>>> root_ptr deals with objects which are reachable from multiple roots,
>>>>>> which have independent lifetime
>>>>>
>>>>> Please provide an example.
>>>>
>>>> i've posted some already
>>>
>>> I'm working on the parser right now but I thought I proved my point with
>>> the following code:
>>>
>>> var temporary = 0;
>>>
>>> var bar = function (object)
>>> {
>>> return 10;
>>> };
>>>
>>> var foo = function ()
>>> {
>>> var object;
>>> var result = function() { return object; };
>>> return function() { return bar( object ); };
>>> };
>>>
>>> for (var i = 0; i < 1000000; ++ i)
>>> console_log((foo())(temporary));
>>
>> after `foo` returns, you only have one root, as neither `result` nor
>> `object` will escape `foo` and `object` will only be referenced by the
>> closure returned by `foo`.
>>
>> `result` is a perfect target for escape analysis. maybe even `object`.
>> you have read about escape analysis, right?
>
> Yes I understand escape analysis and that's exactly why I had to add a
> run-time stack.
I apologize but there was a bug in my code which I just fixed (about
missing variables). And perhaps you and Thiago were right that it's
impossible for Javascript to run without a GC because variables indeed
go out of scope and only the GC can tell whether to keep it or not.
Perhaps I should go back to the C++ world with my root_ptr, now that I
have a better understanding of it all. But I will double check all of
this beforehand.
Thanks again!
-Phil
More information about the Development
mailing list