QNetworkAccessManager Memory leak
Code:
while(1){
QNetworkAccessManager *aa = new QNetworkAccessManager();
QNetworkReply *bb;
QNetworkRequest Request;
Request.
setUrl(QUrl("http://127.0.0.1"));
bb= aa->get(Request);
bb->abort();
bb->close();
bb->deleteLater();
bb = NULL;
delete aa;
aa = NULL;
}
i have a web spider project using QNetworkAccessManager,this code is a example,run this code
you can see the memory no leak,but most people no carefully review the other information in the code's progress
use progress view or windows7 task manager ,you can see the handle-count,up up up
after a while,the progress memory Perhaps still between 30M - 60M
but the handle count has not been reduced.
if the handle count > 1,000,000,the program died
what's the problem,i try to watch QNetworkAccessManager class's code,but no help
it's QNetworkAccessManager class's bug,not my,right?
if it's my problem,how can i fix it,and where:confused:
os:win7 + qt4.8.1
Re: QNetworkAccessManager Memory leak
Since your code never returns to the Qt event loop none of the Qt mechanisms for scheduling later object deletion, opening, reading, closing sockets etc. will ever run. I am surprised that ports for sockets are not exhausted much earlier, but it's hard to say how the Qt code will react to such a pathological usage pattern. Your example is so far from a working web spider implementation it seems largely moot anyway.
You can fix it by understanding that Qt networking is done on an asynchronous basis and that those events need to be serviced.
Re: QNetworkAccessManager Memory leak
In a first attempt insert the processEvents() function of QApplication in your while(1)-loop to give bb->deleteLater() a chance. And delete the line "bb = NULL".
Qt-Doc: QCoreApplication processEvents
Re: QNetworkAccessManager Memory leak
Quote:
Originally Posted by
MadMax411
In a first attempt insert the processEvents() function of QApplication in your while(1)-loop to give
bb->deleteLater() a chance. And delete the line "bb = NULL".
Qt-Doc:
QCoreApplication processEvents
That will not do anything good since the code aborts a request immediately after making it. The whole application is essentially a no-op.
2 Attachment(s)
Re: QNetworkAccessManager Memory leak