Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qt Quick: When a Canvas3D element is deleted, are all its GL resources freed?

Qt Quick: When a Canvas3D element is deleted, are all its GL resources freed?

Scheduled Pinned Locked Moved QML and Qt Quick
memorymemory leakopenglopengl es
6 Posts 3 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Stefan Monov76S Offline
    Stefan Monov76S Offline
    Stefan Monov76
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Yes, see e.g.: http://code.qt.io/cgit/qt/qtcanvas3d.git/tree/src/texture3d.cpp?id=6bbb3a372329ee9d196263997b8c643b59f75581

      Stefan Monov76S 1 Reply Last reply
      2
      • ? A Former User

        Hi! Yes, see e.g.: http://code.qt.io/cgit/qt/qtcanvas3d.git/tree/src/texture3d.cpp?id=6bbb3a372329ee9d196263997b8c643b59f75581

        Stefan Monov76S Offline
        Stefan Monov76S Offline
        Stefan Monov76
        wrote on last edited by
        #3

        @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 entire Canvas3D is deleted (by being removed from the QML object tree).

        ? 1 Reply Last reply
        0
        • Stefan Monov76S Stefan Monov76

          @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 entire Canvas3D is deleted (by being removed from the QML object tree).

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #4

          @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. :-)

          Stefan Monov76S 1 Reply Last reply
          2
          • ? A Former User

            @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. :-)

            Stefan Monov76S Offline
            Stefan Monov76S Offline
            Stefan Monov76
            wrote on last edited by
            #5

            @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.

            mrjjM 1 Reply Last reply
            0
            • Stefan Monov76S Stefan Monov76

              @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.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @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

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved