QList<pointer>::takeFirst() and memory leak question
Hi All!
Can't think clearly today. So, just to be assured, has decided to ask:
I have QList created somewhere in program:
Code:
QList<ExFOLDER *> mapi_folders;
//....
ExFOLDER * folder = new ExFOLDER(CRM_ID,oid);
//...
mapi_folders.append(folder);
after some procedures:
Code:
while(mapi_folders.count() > 0)
{
ExFOLDER * folder = mapi_folders.takeFirst();
//...
delete folder;
}
Do I have memory leaks in this code sample?
Re: QList<pointer>::takeFirst() and memory leak question
yes, if an exception is thrown in line 4; no otherwise.
Re: QList<pointer>::takeFirst() and memory leak question
Quote:
Originally Posted by
caduel
yes, if an exception is thrown in line 4
If you don't know exactly or if you want be absolutely sure, then use a normal iteration scope and afterward do
Code:
qDeleteAll(mapi_folders);
mapi_folders.clear();
Re: QList<pointer>::takeFirst() and memory leak question
Quote:
Originally Posted by
caduel
yes, if an exception is thrown in line 4; no otherwise.
no exceptions for sure;
Quote:
If you don't know exactly or if you want be absolutely sure, then use a normal iteration scope and afterward do
I have not much resources to wait for loopend... and do qDeleteAll(). WINCE Platform. Thought that Object removal when in it is no more necessity there, is good idea. The second(while(mapi_folders.count() > 0)) loop can take long time.
Thanks for yours answers!