Hi,
I've written a software which browses multiple websites containing javascript.
To achieve that, I'm using QWebPage with QWebSettings::JavascriptEnabled.
The problem is that over the time the ram usage is constantly increasing, until more than 1-2 gb of ram is used and then crashes.
I've written a little test snippet to demonstrate the issue.
Ram usage
- Without running the snippet: 7,7mb
- With QWebSettings::JavascriptEnabled set to false: 40mb
- With QWebSettings::JavascriptEnabled set to true: 110mb
If you put some breakpoints, you can see the ram usage increasing with each site.
Do you have any solution so that I can reduce the amount of ram used? I guess the problem is the page/frame isn't deleted because some javascript code is executed (maybe?). If so, any way to force the javascript to stop, once the page is loaded? Or perhaps a way to force the page to delete all its content?
QWebPage page;
page.settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
connect(&page, SIGNAL(loadFinished(bool)), &loop, SLOT(quit()));
for (int i=0; i<2; i++) {
page.
mainFrame()->load
(QUrl("http://www.youtube.com"));
loop.exec();
page.
mainFrame()->load
(QUrl("http://www.youtube.com"));
loop.exec();
page.
mainFrame()->load
(QUrl("http://www.9gag.com"));
loop.exec();
page.
mainFrame()->load
(QUrl("http://www.google.com"));
loop.exec();
page.
mainFrame()->load
(QUrl("http://www.facebook.com"));
loop.exec();
page.
mainFrame()->load
(QUrl("http://www.amazon.com"));
loop.exec();
page.
mainFrame()->load
(QUrl("http://www.twitter.com"));
loop.exec();
page.
mainFrame()->load
(QUrl("http://qt-project.org"));
loop.exec();
page.
mainFrame()->load
(QUrl("http://imdb.com"));
loop.exec();
page.
mainFrame()->load
(QUrl("http://techcrunch.com/"));
loop.exec();
}
QWebPage page;
page.settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
QEventLoop loop;
connect(&page, SIGNAL(loadFinished(bool)), &loop, SLOT(quit()));
for (int i=0; i<2; i++) {
page.mainFrame()->load(QUrl("http://www.youtube.com"));
loop.exec();
page.mainFrame()->load(QUrl("http://www.youtube.com"));
loop.exec();
page.mainFrame()->load(QUrl("http://www.9gag.com"));
loop.exec();
page.mainFrame()->load(QUrl("http://www.google.com"));
loop.exec();
page.mainFrame()->load(QUrl("http://www.facebook.com"));
loop.exec();
page.mainFrame()->load(QUrl("http://www.amazon.com"));
loop.exec();
page.mainFrame()->load(QUrl("http://www.twitter.com"));
loop.exec();
page.mainFrame()->load(QUrl("http://qt-project.org"));
loop.exec();
page.mainFrame()->load(QUrl("http://imdb.com"));
loop.exec();
page.mainFrame()->load(QUrl("http://techcrunch.com/"));
loop.exec();
}
To copy to clipboard, switch view to plain text mode
I'm using Qt 5.1 RC
Bookmarks