Re: Basic question on new and delete
Quote:
Originally Posted by GreyGeek
That I knew, I was just supposing that if they were created by "new" would it matter if they were deleted using the delete operator because they were going out of scope anyway if, as you say, the OS will always get the memory back.
Ok, then no, it wouldn't matter. As a matter of good practice, I would delete them anyway though.
Quote:
Because it inherited from QDialog?
class dlgLogin : public QDialog
An ancestor isn't a parent?
(I told you I was new to C++) :)
No, QDialog is its baseclass, not its parent. The parent is the object you pass as the QWidget* parameter (which can be NULL). 'Baseclass', 'superclass' or 'inherited class' are names for the same C++ OO constructs. 'Parent' (in this context) is a Qt construct and refers to ownership, not inheritance. Reading the comprehensive documentation of QObject will explain it more.
Quote:
So, using "new" as shown below means that "ui.gridMultiProp" is a parent to *model ??
That's correct.
Quote:
Pardon the dumb questions but you'll dealing with someone who has read perhaps too much and it's all jumbled up inside?
It's amazing that I can, using QT, write the app I did and that it works. :D
It is amazing. Did you check your prog for memory leaks :)
Actually, it's a very bad idea to use Qt to learn C++ (not suggesting that you did it this way). It is much better to learn C++ and get confident with it (warts and all), then start using Qt to see how much easier it makes your life! The QObject parent-child model along with the references counted non-QObjects really help cut down on the amount of memory management that you have to worry about (but you still must be wary).
Re: Basic question on new and delete
Once the program has terminated. The OS (Linux and Windows) will be able to use the memory again. Definition of memory leak is during the lifetime of the program.
However, the OS might not be so nice for awhile if the memory leaking program took up ALL memory resources until it finally crashed. But the first example is a safe example. He makesnew object... (usually doing other stuff too ;-) and then the application quits, and the memory - when it is needed. Will be re-used by the OS.
Another issue is memory fragmentation, which can be a bigger problem on Windows I fear.
Re: Basic question on new and delete
Welll I have a very basic query on this matter.. What happens if the application is run continuously where it will have several instances of new.
Lets say at the end of the program it says:
Do you want to quit or continue ?
If the user wants to continue then the main application has not been quit.. so all the instances of "new" that were originally there will again be made..as the program will again run from the beginning .
In such case does QT takes care of freeing the memory..or we have to manually free up all the memory taken by the object ..
Re: Basic question on new and delete
Quote:
Originally Posted by ct
In such case does QT takes care of freeing the memory..or we have to manually free up all the memory taken by the object ..
Qt will delete only objects derived from QObject that have a parent and only if their parent gets deleted.
Re: Basic question on new and delete
so say in case of something like messenger, where one logs out all the objects needs to be manuallly freed so that new instances could be formed for the new sign in procedure ..
Re: Basic question on new and delete
Quote:
Originally Posted by ct
so say in case of something like messenger, where one logs out all the objects needs to be manuallly freed so that new instances could be formed for the new sign in procedure ..
If they aren't QObjects or they have no parents, yes.