Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
4.6.2
-
None
-
Windows XP SP3 32Bit, Windows Vista SP2 32Bit, Visual C++ Express 2008 (cl.exe 15.00.21022.08)
Description
The following code seems to leak memory.
After about 5000 calls the memory increases by 500K. This may not seem much, but I want similar code to run for a couple of days polling an xml-rpc server which causes the memory to increase significantly.
The server called in this example is a locally running apache server. This was also tested with several xml-rpc servers (in those cases the payload sent as POST data was changed accordingly, of course).
fxmlrpctest.h
#ifndef FXMLPRCTEST_H #define FXMLPRCTEST_H #include <QEventLoop> #include <QNetworkAccessManager> class FXmlRpcTest : public QObject{ Q_OBJECT public: FXmlRpcTest(int runs = 5000); ~FXmlRpcTest(); signals: void quit(); public slots: void doIt(); void replyFinished(QNetworkReply*); private: QEventLoop mBlock; int mSequenceNumber; int mRuns; QNetworkAccessManager mNetwork; }; #endif // FXMLPRCTEST_H
fxmlrpctest.cpp
#include "fxmlrpctest.h" #include <iostream> #include <QNetworkRequest> #include <QNetworkReply> #include <QTimer> FXmlRpcTest::FXmlRpcTest(int runs) : QObject(NULL), mBlock(), mSequenceNumber(0), mRuns(runs), mNetwork(this) { connect(&mNetwork, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); } void FXmlRpcTest::replyFinished(QNetworkReply* reply) { QString response = QString::fromUtf8(reply->readAll()); reply->close(); reply->deleteLater(); if (reply->error()) { std::cout << "Error: " << reply->errorString().toStdString() << std::endl; } std::cout << response.toStdString() << std::endl; mBlock.quit(); } void FXmlRpcTest::doIt() { if (mSequenceNumber > mRuns) { emit quit(); return; } mSequenceNumber++; std::cout << "Request number : " << mSequenceNumber << std::endl; QString payload = "birthdate=12%2F01%2F1234&showpng=1"; QByteArray ba = payload.toLatin1(); QNetworkRequest req = QNetworkRequest(QUrl("http://localhost/xampp/biorhythm.php")); mNetwork.post(req,ba); mBlock.exec(); QTimer::singleShot(100, this, SLOT(doIt())); } FXmlRpcTest::~FXmlRpcTest() { }
main.cpp
#include <QCoreApplication> #include <QTimer> #include "fxmlrpctest.h" int main(int argc, char *argv[]) { int runs = 50000; if (argc > 1) { runs = QString(argv[1]).toInt(); } QCoreApplication a(argc, argv); FXmlRpcTest w(runs); QTimer::singleShot(500, &w, SLOT(doIt())); a.connect(&w, SIGNAL(quit()), &a, SLOT(quit())); a.exec(); return 0; }