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.
  • S Offline
    S Offline
    Stefan Monov76
    wrote on 29 Nov 2016, 17:52 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 30 Nov 2016, 18:33 last edited by
      #2

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

      S 1 Reply Last reply 1 Dec 2016, 13:29
      2
      • ? A Former User
        30 Nov 2016, 18:33

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

        S Offline
        S Offline
        Stefan Monov76
        wrote on 1 Dec 2016, 13:29 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 1 Dec 2016, 14:13
        0
        • S Stefan Monov76
          1 Dec 2016, 13:29

          @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 1 Dec 2016, 14:13 last edited by A Former User 12 Jan 2016, 16:23
          #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. :-)

          S 1 Reply Last reply 1 Dec 2016, 15:21
          2
          • ? A Former User
            1 Dec 2016, 14:13

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

            S Offline
            S Offline
            Stefan Monov76
            wrote on 1 Dec 2016, 15:21 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.

            M 1 Reply Last reply 1 Dec 2016, 15:36
            0
            • S Stefan Monov76
              1 Dec 2016, 15:21

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

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 1 Dec 2016, 15:36 last edited by mrjj 12 Jan 2016, 15:36
              #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

              6/6

              1 Dec 2016, 15:36

              • Login

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