Re: Dynamic memory release
It releases the memory it allocated itself.
If you store pointers in the QVector, and those should happen (because they don't need to) to have been allocated on the heap (with new)... then this allocated memory will not be freed.
One simple solution is to put smart pointers (a boost::shared_ptr, or Qt 4.5's upcoming smart ptrs) inside such containers.
Another way would be to call qDeleteAll before clearing the container.
HTH
Re: Dynamic memory release
Hi ,
I am not storing pointer's in QVector...
I have a QHash<int, pointer>
The pointer in Hash points to a QVector, before i remove a key from hash, i have called delete on the pointer (to ensure that all the memory alloted to QVector its pointing is released).
Is this enough or should i have to clear the QVector that the pointer points to ?.
Re: Dynamic memory release
With respect to memory leaks: deleting that pointer is enough.
The memory allocated by the QHash itself is managed automatically. You just have to free the memory you allocated.
Re: Dynamic memory release
I have already done that (I have done a delete on the pointer in the Hash before removing the key), but my app shows a constant increase in the VIRTUAL MEMORY (using pmap), only while handling the data related to QHash<int, pointer>.
I suspect only the pointer in QHash, pointing to QVector ....
I am running 'top' command on the exe, at regular intervals and its showing a constant increase in Virtual Memory and resident memory. (Specifically in the anon Block, i think its Heap and related to Dynamic Memory i am using)
Is there any way i can find out, why this is happening ? or which data in my app is taking memory and not releasing back to the Heap???....
Is there any better way to detect Memory Leak in Qt.
I have used Valgrind, but its at very low level...
Re: Dynamic memory release
put qDebug in all dtors of your object and count number of messages after deleting or put breakpoints in all dtors and trace them or you can use 'valgrind' under Linux.