AssignToHTMLImageElement memory leak
-
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_OBJECTQ_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]
-
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.
-
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...