PDA

View Full Version : QList<pointer>::takeFirst() and memory leak question



AcerExtensa
9th July 2009, 12:33
Hi All!
Can't think clearly today. So, just to be assured, has decided to ask:
I have QList created somewhere in program:


QList<ExFOLDER *> mapi_folders;
//....
ExFOLDER * folder = new ExFOLDER(CRM_ID,oid);
//...
mapi_folders.append(folder);


after some procedures:


while(mapi_folders.count() > 0)
{
ExFOLDER * folder = mapi_folders.takeFirst();
//...
delete folder;
}


Do I have memory leaks in this code sample?

caduel
9th July 2009, 12:49
yes, if an exception is thrown in line 4; no otherwise.

Lykurg
9th July 2009, 13:02
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

qDeleteAll(mapi_folders);
mapi_folders.clear();

AcerExtensa
9th July 2009, 13:20
yes, if an exception is thrown in line 4; no otherwise.
no exceptions for sure;


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!