PDA

View Full Version : To delete or not to delete....



philwinder
21st April 2008, 09:11
Hey,
I have a pretty fundamental question that I cannot seem to find the answer for in either the documentation or the forums.

Which items should I call delete xyx; on, and which items do I not? Is there a hard-fast rule? Since I read the other day that all items derived from QWidget, do not need to be deleted because Qt deletes them automatically.

I say this because before I removed the deletes, I was getting lots of crashes. But now I worry that I am creating lots of memory leaks.

Thanks,

Phil Winder

janus
21st April 2008, 09:21
http://www.qtcentre.org/forum/f-qt-programming-2/t-creatingdeleting-objects-memory-leaks-12708.html

philwinder
21st April 2008, 10:43
Thanks for that Janus,
but what about new classes that I have derived from say QObject. Would I have to implement my own delete's in the destructor, or does the QObject take care of that?

Cheers,
Phil

aamer4yu
21st April 2008, 10:47
May be this (http://doc.trolltech.com/4.3/objecttrees.html) will help u understand more :)

philwinder
21st April 2008, 11:01
Ahhh, thanks aamer4yu.
So would I have to reimplement the children() function in my classes?
E.g. for an XML parser class, called QgetXMLData, how would I implement a child deleter? Or could I just cheat and set all the new objects' parent to the parent of QgetXMLData? :eek:

Cheers again,
Phil