I want to download several pages, do something with them, and free the memory they’ve been using. Here, the same page is downloaded 10 times:
#include <QApplication>
#include <QtNetwork/QNetworkProxy>
#include <QtWebKitWidgets/QWebView>
void Load(char *url) {
QWebView web_view;
QEventLoop loop;
QObject::connect(&web_view, SIGNAL(loadFinished(bool)), &loop, SLOT(quit()));
web_view.setUrl(QUrl(url));
loop.exec();
}
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QWebSettings::setMaximumPagesInCache(0);
QWebSettings::setObjectCacheCapacities(0, 0, 0);
for (int i = 0; i<10; ++i) {
Load("http://www.huffingtonpost.com/");
QWebSettings::clearMemoryCaches();
QWebSettings::clearIconDatabase();
printf("%d\n", i);
}
return a.exec();
}
I would expect that QWebView is destructed at the end of each Load(), but for some reason memory usage is increasing up to 200MB and does not decrease even after we reach “return a.exec()”.
Why memory consumption is this high? How can I free it?
P.S.: I tried adding web_view.deleteLater() at the end of Load(), but it was of no avail.
↧