[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: Memory question
From:       Leon Widdershoven <l.widdershoven () fz-juelich ! de>
Date:       1999-08-02 5:53:31
[Download RAW message or body]

Hi,

The answer to what you ask can not easily be given; 
it depends on the memory allocation scheme you use.

If you make your own dialog, and create it with 
MyDialog *mydialog = new MyDialog;

the you MUST delete it with delete mydialog.

If you have:
MyDialog mydialog;

the it will be destructed when it runs out of
context (this is at a "}"). The memory will 
be freed then.

Of course you must also not forget to delete
the data structures you allocate with new in
your dialog; this must be done in the destructor
of the dialog.
One exception is QWidgets with your dialog as parent,
they will be destructed when the dialog gets destructed.
I think (Kalle Dalheimers book on Qt programming thinks)
that one should not destruct hi/herself widgets with 
another widget as parent. [I hope I interpreted that right]

In general:
- Everything allocated with new must be deleted with delete
- Everything allocated with new[] must be deleted with delete
 (this inclused char *foo = new char[1024];)
- Everything allocated like: Foo foo; gets deleted automatically.
- Every static function is not allocated by you and should 
 not be deleted by you ( QFileDialog::getSaveFileName() or so).

It is interesting to use a debugger like ddd or of course 
kdbg to step through the destructors; you will see then what
is done during destruction/construction...

Leon

Herwin Jan Steehouwer wrote:
> 
> Hi,
> 
> I have a little memory question, when i make Dialogs or TabDialog etc,
> they are closed with accept(), but that is not removing the dialog.
> 
> How can i be shure the dialog is removed from memory, because the memory
> is increasing every time i open a window !?
> 
> tanx
> 
> HJ
> 
> Herwin Jan Steehouwer
>   herwinjs@palet.nl                 http://www.caiw.nl/~herwinjs
>   steehouwer@kde.org              KDE developer http://www.kde.org

-- 
In a world without walls and fences,  l.widdershoven@fz-juelich.de
who needs Windows and Gates?          Institute of Plasma physics (IPP)
                                      Forschungszentrum Juelich GmbH

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic