On Wednesday, 16 October 2013 at 06:53:24 UTC, Jacob Carlborg
wrote:
In D, using the GC, you can call GC.addRoot to avoid that
problem.
Yes, I was thinking of using core.memory stuff to stop things
from being collected, or perhaps scan inside Qt memory. For
instance, you could store a class pointer inside of a QObject
with setProperty. One option is to have QObject in D hold an
array of pointers for keeping references to children, etc. There
are some tricky parts.
---
// Okay, this is a root object, when do we collect this?
auto widget = new QWidget();
// This is just a free object, not attached to anything.
// Clearly we can collect this.
auto label = new QLabel("Hello!");
auto layout = new QHBoxLayout;
layout.addWidget(label);
// Wait, now label implicitly becomes a child object of widget.
// its memory is now managed by that, so when do we collect it?
widget.setLayout(layout);
// Does this work?
assert(label.parent is widget);
---
So in other words, I haven't yet reached a point where I think,
"Yes, I have covered every case and I'm happy."