Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, January 2008
Qt::WA_DeleteOnClose - memory usage does not diminish on closing a widget


Message 1 in thread

Hello, everyone

I've just read in the manual about Qt::WA_DeleteOnClose flag and decided
to give it a try. I've set up two widget classes: dfMainWindow and
dfChildWindow and have set Qt::WA_DeleteOnClose in the constructors of
both. Now I'm creating dfChildWindow instance from dfMainWindow like
this:

void dfMainWindow::on_action_NewChild_triggered()
{
    dfChildWindow *ChildWindow = new dfChildWindow();
    ChildWindow->show();
}

So, I've run the program and've opened 5 ChildWindow widgets. Then I've
measured memory usage of my program before and after closing those 5
windows.

$ ps axo pid,vsz,rss,pmem,time,comm | grep myprog
10299  34388 16280  1.6 00:00:01 myprog
$ ps axo pid,vsz,rss,pmem,time,comm | grep myprog
10299  34388 16288  1.6 00:00:01 myprog


In spite of my expectations, the memory occupied by the program has not
decreased, but actualy increased. I've checked if the destructor of
dfChildWindow is being called, which was true. So I guess its not a QT
issue. However, if somebody on the list knows what is actually happening
(why memory is not being freed), please respond.
Thanks




--
 [ signature omitted ] 

Message 2 in thread

Hi dima
you can use valgrind (http://valgrind.org/) to view if there are memory
leaks in your application

AFAIK ps is no accurate on show memory usage use pmap for more acurate
results.

Message 3 in thread

You don't see the memory being reduced because no other application needs it. 
All processes are greedy for memory, and they will never release memory 
before they have to.

You should search the net for this, because it's a very long and technical 
discussion. At least if you want the accurate version. A google search 
for "measure memory use" gave a good set of hits.

Bo.

On mandag den 21. Januar 2008, dima wrote:
> Hello, everyone
>
> I've just read in the manual about Qt::WA_DeleteOnClose flag and decided
> to give it a try. I've set up two widget classes: dfMainWindow and
> dfChildWindow and have set Qt::WA_DeleteOnClose in the constructors of
> both. Now I'm creating dfChildWindow instance from dfMainWindow like
> this:
>
> void dfMainWindow::on_action_NewChild_triggered()
> {
>     dfChildWindow *ChildWindow = new dfChildWindow();
>     ChildWindow->show();
> }
>
> So, I've run the program and've opened 5 ChildWindow widgets. Then I've
> measured memory usage of my program before and after closing those 5
> windows.
>
> $ ps axo pid,vsz,rss,pmem,time,comm | grep myprog
> 10299  34388 16280  1.6 00:00:01 myprog
> $ ps axo pid,vsz,rss,pmem,time,comm | grep myprog
> 10299  34388 16288  1.6 00:00:01 myprog
>
>
> In spite of my expectations, the memory occupied by the program has not
> decreased, but actualy increased. I've checked if the destructor of
> dfChildWindow is being called, which was true. So I guess its not a QT
> issue. However, if somebody on the list knows what is actually happening
> (why memory is not being freed), please respond.
> Thanks
>
>
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body. List archive and information:
> http://lists.trolltech.com/qt-interest/



-- 
 [ signature omitted ] 

Message 4 in thread

Quoting dima <dima@xxxxxxxxxx>:

> Hello, everyone

[snip]

This is standard on just about all OSes. Freed memory is never returned to the
OS. Instead it is made available to the pool for reuse by the application.

A+
Paul

--
 [ signature omitted ]