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

List:       kde-devel
Subject:    Re: Session Management with KUniqueApplication
From:       Lubos Lunak <l.lunak () suse ! cz>
Date:       2003-09-30 13:24:30
[Download RAW message or body]

On Tuesday 30 of September 2003 14:51, David Jarvie wrote:
> On Monday 29 Sep 2003 2:36 pm, Lubos Lunak wrote:
> > On Friday 26 of September 2003 23:22, David Jarvie wrote:
> > >         UniqueApp* app = new UniqueApp
> > >         if (app->isRestored()) {
> > >           // Process is being restored by session management.
> > >           // ... whatever is needed ...
> > >         }
> > >         return app->exec();
> >
> >  You're leaking the app object. Why not simply make it stack allocated?
>
> Does this matter - isn't everything automatically deallocated when the app
> exits? I happened also to notice the existence of KStaticDeleter class
> today, whose purpose raises the same questions. Surely an application which
> has exited can't retain any resources.

 Deallocated yes, but not destroyed - the destructors are not run. In this 
case it's not that critical, as it's not that rare that apps exit abnormally 
(crash, whatever).

 I rather wanted to point out about this general style of writing things, 
which can leak memory. I've seen already a couple of places in KDE where it's 
only
{
MyFoo* foo = new MyFoo;
foo->something();
return;
}

 which has 'delete foo;' missing. If you write something like
{
MyFoo* foo = new MyFoo;
foo->whatever();
delete foo;
}

you can as well write it as 
{
MyFoo foo;
foo.whatever();
}

 You save one dynamic allocation/deallocation (which usually doesn't really 
matter), and you also don't have to bother about making sure you don't leak 
memory, because 'foo' will be automatically destroyed when leaving the block.

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak@suse.cz , l.lunak@kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/

 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

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