Discussion:
[webkit-help] How to clear memory held by QtWebkit?
Bono Damodi
2016-12-13 16:34:54 UTC
Permalink
Hello,
is there a way to deinitialise QtWebkit in runtime completely? For example
for this code:

#include <QApplication>
#include <QGraphicsWebView>
#include <QUrl>
#include <QTimer>

QGraphicsWebView* graphicsWebView;

class Deleter : public QObject
{
Q_OBJECT
public slots:
void deleteWebView()
{
delete graphicsWebView;
}
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
graphicsWebView = new QGraphicsWebView;
graphicsWebView->setUrl(QUrl("http://www.google.com"));
Deleter d;
QTimer::singleShot(10000, &d, SLOT(deleteWebView()));
return app.exec();
}

#include "main.moc"

After deleting graphicsWebView object there is still used about 2mb of
physical memory (more than 6 mb of virtual memory) by Webkit's OSAllocator
(I tracked mmap's calls by OSAllocator and then correlated with
/proc/pid/smaps). Much of the memory seems to be requested
by JSC::JIT::compile function.

Is there some way to completely clean QtWebkit after it was initialised?

This is Qt 4.8

Best regards
Konstantin Tokarev
2016-12-13 16:52:52 UTC
Permalink
Post by Bono Damodi
Hello,
#include <QApplication>
#include <QGraphicsWebView>
#include <QUrl>
#include <QTimer>
QGraphicsWebView* graphicsWebView;
class Deleter : public QObject
{
    Q_OBJECT
    void deleteWebView()
    {
        delete graphicsWebView;
    }
};
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    graphicsWebView = new QGraphicsWebView;
    graphicsWebView->setUrl(QUrl("http://www.google.com"));
    Deleter d;
    QTimer::singleShot(10000, &d, SLOT(deleteWebView()));
    return app.exec();
}
#include "main.moc"
After deleting graphicsWebView object there is still used about 2mb of physical memory (more than 6 mb of virtual memory) by Webkit's OSAllocator (I tracked mmap's calls by OSAllocator and then correlated with /proc/pid/smaps). Much of the memory seems to be requested by JSC::JIT::compile function.
Is there some way to completely clean QtWebkit after it was initialised?
To clear code compiled by JIT it should be enough to QWebSettings::clearMemoryCaches()

However, note that it's not ever possible to clear 100% of memory allocated by WebKit (any port), because a lot of data structures are by design NeverDestroyed (look for DEFINE_STATIC_LOCAL in your QtWebKit version).
Post by Bono Damodi
This is Qt 4.8
Please consider upgrading to Qt 5. Qt 4.8 have reached EOL, and all compatible QtWebKit versions are horribly out of date.
Post by Bono Damodi
Best regards
,
_______________________________________________
webkit-help mailing list
https://lists.webkit.org/mailman/listinfo/webkit-help
--
Regards,
Konstantin
Loading...