Qt Quick: When a Canvas3D element is deleted, are all its GL resources freed?
-
When a Canvas3D element is deleted, are all its GL resources (that I've created with GL calls) freed? E.g. textures, VBOs, shaders.
I prefer answers that include a reliable reference.
-
-
@Wieland: Thanks but I think you misunderstood me. I'm not asking what happens when a
Canvas3DTexture
object is deleted/GC'd. I'm asking what happens to the textures when the entireCanvas3D
is deleted (by being removed from the QML object tree). -
@Stefan-Monov76 The Canvas and all its textures etc are QObjects themselves and form a QObject tree. You can see this e.g. here:
QJSValue CanvasContext::createTexture() { if (checkContextLost()) return QJSValue(QJSValue::NullValue); CanvasTexture *texture = new CanvasTexture(m_commandQueue, this); QJSValue value = m_engine->newQObject(texture); qCDebug(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ << "():" << value.toString(); addObjectToValidList(texture); return value; }
Here, the new CanvasTexture object is created as a QObject child of this canvas context. So once the canvas object gets destroyed in QML, be it explicitly or by the JS garbage collector, all the children of the canvas get destroyed, too. And, as seen in the previous posting, the destructors of these children (textures etc) release their GL resources, too. So we have perfect clean-up, unless there's a bug somewhere of course. :-)
-
@Wieland: Thanks, that's convincing. But still I'm going to abstain from relying on it, since it's undocumented and may change in future versions.
-
@Stefan-Monov76
The automatic deletion of QObject childs by the parents is used in whole Qt frame work and
is fully documented and will not change in any version.
http://doc.qt.io/qt-5/objecttrees.html