PDA

View Full Version : When to delete QNetworkReply?



QPlace
10th November 2008, 11:41
Calling "post" on QNetworkAccessManager returns pointer to QNetworkReply that is later passed to a connected slot as a parameter.

Questions:
Who is responsible to deleting it ?
If it should be deleted manually - where is the right place to do it?
If it is managed by Qt - when it is deleted?

rbp
10th February 2009, 01:11
Currently I'm using the slot to clean up the memory (the QNetworkAccessManager and its children).
But is the slot called in all cases? - including when the server has an error or times out.
If not then I have a potential memory leek.

jpn
10th February 2009, 13:10
From QNetworkAccessManager::~QNetworkAccessManager() docs:


Destroys the QNetworkAccessManager object and frees up any resources. Note that QNetworkReply objects that are returned from this class have this object set as their parents, which means that they will be deleted along with it if you don't call QObject::setParent() on them.

rbp
10th February 2009, 22:01
yeah that's how I clean up the memory, with the QNetworkAccessManager destructor. I call it after the request because I'm relying on it's slot:
http://doc.trolltech.com/4.4/qnetworkaccessmanager.html#finished

But I'm not sure if the slot is called in all cases. My app has a lot of network activity so I don't want a memory leak here.

jpn
11th February 2009, 11:43
yeah that's how I clean up the memory, with the QNetworkAccessManager destructor. I call it
Do you mean that you call a destructor explicitly?

rbp
11th February 2009, 12:46
Do you mean that you call a destructor explicitly?
No, indirectly:

delete reply->manager();

Do you know if the slot is always called, including for errors and timeouts?
I can clean up the memory fine if the slot is always called.