Qt 5.0.2 Memory leak on simple qWebView
I have a problem with a memory leak happening while having a QWebView
opened on Qt 5.0.2. The only thing I do is I open a QWebWindow with a
simple local webpage. The script calls the server by doing an ajax request
and repeats the action indefinitely. There is no data saved in cache,
localStorage or sessionStorage. The problem is though that the application
takes too much memory even after an hour of running. (over 300Mb).
I'm not sure if this is a qt-related problem or a javascript-related problem.
Here's the code I use:
#include <QWebFrame>
#include <QWebElementCollection>
#include <QNetworkDiskCache>
#include <QDesktopWidget>
#include <QWebHistory>
#include "mainwindow.h"
MainWin::MainWin(QWidget * parent) : QWebView(parent)
{
m_network = new QNetworkAccessManager(this);
m_cache = new QNetworkDiskCache(this);
m_cache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
+ "/test");
m_cache->setMaximumCacheSize(0);
m_network->setCache(m_cache);
page()->setNetworkAccessManager(m_network);
page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled,
true); // enable inspector
// local content can access remote urls
page()->settings()->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,
true);
// enable javascript
page()->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
// Plug-ins must be set to be enabled to use plug-ins.
page()->settings()->setAttribute(QWebSettings::PluginsEnabled,true);
// Images are automatically loaded in web pages.
page()->settings()->setAttribute(QWebSettings::AutoLoadImages,true);
page()->settings()->setMaximumPagesInCache(0);
page()->settings()->setObjectCacheCapacities(0,0,0); // causing slight
flicker on refresh
page()->settings()->clearMemoryCaches();
page()->history()->setMaximumItemCount(0);
// enable local storage
page()->settings()->enablePersistentStorage("C:\\data\\");
// hide the vertical scrollbar
page()->mainFrame()->setScrollBarPolicy(Qt::Vertical,
Qt::ScrollBarAlwaysOff);
page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal,
Qt::ScrollBarAlwaysOff);
// Signal is emitted before frame loads any web content:
QObject::connect(page()->mainFrame(),
SIGNAL(javaScriptWindowObjectCleared()),
this, SLOT(addJSObject()));
setUrl(startURL);
initEffects();
}
void MainWin::addJSObject() {
}
/*
* EFFECTS
*/
void MainWin::initEffects() {
resize(500, 300);
move(0, 0); // left top corner
}
void MainWin::resize(int width, int height) {
setGeometry(QRect(this->x(), this->y() - (height - this->height()),
width, height));
}
the HTML:
<html lang="en">
<head>
<title>Details</title>
<script type="text/javascript" src="./js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="./js/connection.js"></script>
</head>
<body>
<div>page loaded: <span id="times">0</span> times</div>
</body>
</html>
and the Javascript:
jQuery(document).ready(function($) {
var counter = 0;
var refreshData;
refreshData = function() {
counter++;
var jData = '{"test":"test"}';
var request = $.ajax({
type: "POST",
url: "http://qt.digia.com/",
dataType: "json",
data: { jsonData: jData },
timeout: 15000, // 15 secs
complete: function(response) {
console.log(response);
delete response;
$('#times').html(counter);
// no need to hide the window, usual behavior
refreshDataTimeout = setTimeout(refreshData, 1000);
}
});
request.onreadystatechange = null;
request.abort = null;
request = null;
delete request;
}
refreshData();
});
No comments:
Post a Comment