Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. AssignToHTMLImageElement memory leak

AssignToHTMLImageElement memory leak

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    Vitalich
    wrote on last edited by
    #1

    I'm trying to build a simple QT+HTML+JS+OpenCV application, that just shows the video from webcam on the html doc (shown by QWebView).

    I've noticed that every call to assignToHTMLImageElement increases memory allocated by the app. I beleive that shouldn't be a normal behavior. What am I doing wrong?

    Here is the code:
    @
    int main(int argc, char *argv[])
    {

    QApplication a(argc, argv);

    MyClass w;

    w.show();

    return a.exec();

    }

    class MyClass : public QMainWindow
    {

    <... some code ...>

    Ui::MyClassClass ui;

    PureCaptureQThread cap;

    };

    class PureCaptureQThread: public QThread
    {
    Q_OBJECT

    Q_PROPERTY(QImage image READ getImage);

    <... some code ...>

    QImage getImage();

    QImage m_image;

    signals:

    void newFrame();

    };

    MyClass::MyClass(QWidget *parent, Qt::WFlags flags)

    : QMainWindow(parent, flags)

    {

    <... some code ...>

    ui.webView->page()->mainFrame()->addToJavaScriptWindowObject("cap", &cap);

    }
    @

    HTML:
    @
    function loadImage() {

        cap.image.assignToHTMLImageElement(document.getElementById("m_frame"));
    
    }
    
    function initialize() {
    
        cap.newFrame.connect(loadImage);
    
    }
    

    <body >
    <img id="m_frame" width="640" height="480" />
    </body>
    @

    [edit: Added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vitalich
      wrote on last edited by
      #2

      Thanks SGaist for improving the message.

      1 Reply Last reply
      0
      • T3STYT Offline
        T3STYT Offline
        T3STY
        wrote on last edited by
        #3

        I'm not sure how it works but shouldn't javascript's garbage collector handle this? I guess each time you assign an image, the image data gets cached into memory and eventually garbage collected if not used. Maybe try to manually invoke the GC, but beware of any (bad) consequences.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vitalich
          wrote on last edited by
          #4

          Thanks, I'll try right now.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vitalich
            wrote on last edited by
            #5

            T3STY,

            Would you be so kind and point me to any doc on how to force GC? I've googled this, but foung nothing.

            Thanks

            1 Reply Last reply
            0
            • T3STYT Offline
              T3STYT Offline
              T3STY
              wrote on last edited by
              #6

              Hmm... fat chance...
              http://stackoverflow.com/a/8033043
              Seems like javascript's GC cannot be manually triggered. Although, if you remove all references to an object, that object's data is going to be GC-ed and freed. Unfortunately, it doesn't seem to be your case...

              1 Reply Last reply
              0
              • V Offline
                V Offline
                Vitalich
                wrote on last edited by
                #7

                ok, thanks in any way

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  Vitalich
                  wrote on last edited by
                  #8

                  Noticed, that memory usage grows up to 1492 Mb only, then stops growing.

                  1 Reply Last reply
                  0

                  • Login

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