[Development] Qt 5.9's new garbage collector documentation? + root_ptr

Thiago Macieira thiago.macieira at intel.com
Fri Jul 7 08:07:02 CEST 2017


On quinta-feira, 6 de julho de 2017 20:48:27 PDT Phil Bouchard wrote:
> > How well does root_ptr operate when there are cyclic references?
> > JavaScript
> > objects can refer to each other, so how do you propose the engine handle
> > that case?
> 
> It's very easy.  Every time a node_ptr is created, it enlists the
> pointee object to its associated root_ptr.  When the root_ptr is
> destroyed then all associated objects in that list are destroyed as
> well.  This is how cyclic references are guaranteed to be destroyed
> deterministically.

In other words, "it doesn"t".

In the JS world, if those two objects refer to each other and nothing else 
refers to them, then they both can be garbage-collected.

> > Nor are we. Show us that it working and we'll take a chance. A theoretical
> > solution with no real-life implementation is not for us.
> > 
> > Have you impemented any engine for garbage collected languages using
> > root_ptr? How well does root_ptr work with the Python engine? Or a Java
> > VM? Lua? Ruby? Any scripting language VMs implemented using it?
> 
> No but it works well with neural networks which I think is a good
> example of a worse case situation:
> https://github.com/philippeb8/root_ptr/blob/master/example/t100_test1.cpp

No, I don't think it's a good analogy. I'dl ike to see it in the engine of a 
scripted language.

> > If the order of destruction according to the language is undefined, then
> > the order in which root_ptr destroys it is not relevant and it can't be
> > considered a plus. In fact, having it deterministic could be a negative
> > asset, since someone writing this code will never be exposed to
> > undefinedness of their code.
> I certainly think it's a plus for debugging purposes.  And I fail to
> understand the advantage of the undefinedness of the code.

The other engines are the problem. Granted, that won't happen for QML, since 
there's only one engine. But for JS, developers have to cope with the 
differences in behaviour.

> > By the way, how does it break the cycle?
> 
> Like I was saying before, node_ptr enlists each pointee object to the
> associated root_ptr and when the root_ptr is destroyed then everything
> gets wiped out.

See above. Your answer is "it doesn't break the cycle".

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list