RFC: singletons and memory management

Maximilian Kossick maximilian.kossick at googlemail.com
Thu Sep 11 14:00:36 CEST 2008


On Thu, Sep 11, 2008 at 1:50 PM, Jeff Mitchell
<kde-dev at emailgoeshere.com> wrote:
> Leo Franchi wrote:
>> I was responding to eean's point, not yours :)
>
> I think you mean my point :-)
>
> Anyways, I had understood part of the problem to be that singletons
> remaining open as the program closes ends up causing crashes due to
> accessing other deleted objects, etc. (otherwise, there isn't any reason
> to clean up/delete these singletons, other than pedantry).
>
> So, if this is the case, then if a singleton is deleted, then called
> again via instance and re-created, then we're in the same situation as
> before where the singleton is likely to remain open as the program
> closes, causing a crash on exit when it's finally destroyed.
>
But they are not created automatically anymore. Instead one has to
call the ctor explicitly. That's currently done somewhere in App. If
the order of destruction of our singletons is ok, we won't have any
problems. Otherwise it will crash at some point, either by accessing a
null pointer or by accessing an already deleted object (the former is
preferable because it fails fast).

So instead of figuring out a policy for singletons (which will be
obsolete anyway when I get around to finish the application state
management after 2.0) we should fix the singleton dependencies and
destroy them in the correct order.
Cheers, Max


More information about the Amarok-devel mailing list