T
T
tsarevfs2015-01-15 18:15:02
Qt
tsarevfs, 2015-01-15 18:15:02

How does garbage collection work in Qt?

How much can you rely on the Qt garbage collector? In particular, we are interested in the option when some class returns raw pointers. For example:

QNetworkReply * reply = networkAccessManager_->post(request, params.encodedQuery());

The documentation says:
QNetworkAccessManager::~QNetworkAccessManager() 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.

Remarkably, when the destructor is called, all resources generated by it, including QNetworkReply, will be deleted. But if the manager lives long enough, does it mean that all QNetworkReply created by him will hang in memory? At least not very clear how he could avoid it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2015-01-15
@tsarevfs

The assembly works according to a hierarchical model - the class that generated the objects destroys the children when it is deleted (by sending them a signal).
If you want to improve - delete it yourself, nothing terrible will happen.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question