RFC: singletons and memory management
Leo Franchi
lfranchi at kde.org
Thu Sep 11 05:01:27 CEST 2008
On Sep
> What happens is that if you call "delete Singleton::instance()", then
> the object pointed to by s_instance is freed, but s_instance is never
> reset to zero. So the next time you call Singleton::instance(), it
> will hand back the memory location where the object used to be, and
> you'll get a segfault. You need to call a static Singleton::destroy()
> member to set the s_instance pointer to zero after the object is
> deleted, so that the next time Singleton::instance() gets called, it
> will create a new object. You could also use a "smart" pointer like
> auto_ptr or QPointer that automatically set to zero when they're
> deleted, but I personally prefer the static destroy() method. At any
> rate, the Singleton classes in Amarok should be a little smarter about
> their memory management.
I was responding to eean's point, not yours :) I agree with you, and i
think we should have some smarter deletions---imho, using QPointers
would work well too.
leo
---
Leo Franchi (650) 704 3680
Tufts University 2010
lfranchi at kde.org
leonardo.franchi at tufts.edu
More information about the Amarok-devel
mailing list