
Originally Posted by
GreyGeek
As I understand it C++ does NOT guarantee that the memory is freed. That is your job. And, I read somewhere that delete[] is the prefered form of that command, even if your pointer isn't an array.
That's one of the beneies of using QT. If your class objects inherit from QObject or QWidget then QT's automatic garbage collection takes over, much as Java does. If your class objects don't inherit from those two QT objects then it's YOUR responsibility to make sure they get deleted before they lose scope.
This is incorrect, the memory is always released back to the operating system at program termination. However, this is still technically a memory leak and it is good practice to use 'delete p' on your pointer.
delete[] p should only used on pointers that were assigned to arrays created with new type[], e.g:
int* p = new int; // delete with 'delete p;'
int* a = new int[5]; // delete with 'delete[] a;'
int* p = new int; // delete with 'delete p;'
int* a = new int[5]; // delete with 'delete[] a;'
To copy to clipboard, switch view to plain text mode
Bookmarks