Lee YongGu
Lee YongGu

Reputation: 11

QtWebkit QWebView setUrl Memory Leak

The virtual memory usage of my simple qtwebkit application increases forever. My qtwebkit app simply loops webView->setUrl(QUrl(QStringLiteral("about:blank")), as follows,

QWebView* webView = new QWebView(centralWidget);
webView->setObjectName(QStringLiteral("webView"));
webView->setGeometry(QRect(0, 0, width, height));

while (true)
{
    webView->setUrl(QUrl(QStringLiteral("about:blank")));
    msleep(1); // sleep 1 millisecond
}

I think the memory usage should be stable in this case, however, the result is not. What's the matter? some kind of clearing is required to use setUrl() multiple times?

Upvotes: 1

Views: 1223

Answers (1)

demonplus
demonplus

Reputation: 5801

Unfortunately this is normal for QtWebKit and will be never fixed because it is recommended to use QtWebEngine now.

About memory leaks: https://bugreports.qt.io/browse/QTBUG-36530

There is a number of techniques you can use to clear memory like:

QWebSettings::globalSettings()->clearMemoryCaches();

See here: http://forum.qt.io/topic/10832/memory-size-increases-per-page-load

But usually this is not very helpful and you will have memory leaks as far as you will use QtWebKit. If you are developing new project and your platform supports QtWebEngine, you should think about using it.

Upvotes: 3

Related Questions