[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about memory management
From: |
David Chisnall |
Subject: |
Re: Question about memory management |
Date: |
Fri, 7 Jun 2013 09:38:39 +0100 |
On 7 Jun 2013, at 09:30, "Graham Lee" <address@hidden> wrote:
> Should this be wrapped in if(self == [Singleton class])? I've seen that used
> to guard against this +initialize being called multiple times when a subclass
> is used that doesn't override the method.
Good catch. The answer is... maybe. Typically, singletons don't support
subclassing, because the semantics are a bit interesting. It's often better,
if you have a singleton that may want extending, to provide some delegate
mechanism. Or, alternatively, a way of setting the singleton instance to use.
If you expect subclasses, then you need to be a bit more clever to ensure that
everything that tries to access the object gets the subclass version.
Traditionally, you'd do that by adding a category on the superclass that
replaced +sharedInstance with a call to your replacement. If two different
libraries try to do this, however, the behaviour is undefined.
David
-- Sent from my Apple II
- Re: Question about memory management, (continued)
- Re: Question about memory management, Graham Lee, 2013/06/04
- Re: Question about memory management, Germán Arias, 2013/06/04
- Re: Question about memory management, Graham Lee, 2013/06/05
- Re: Question about memory management, Germán Arias, 2013/06/05
- Re: Question about memory management, Graham Lee, 2013/06/05
- Re: Question about memory management, Germán Arias, 2013/06/05
- Re: Question about memory management, Ivan Vučica, 2013/06/06
- Re: Question about memory management, Maxthon Chan, 2013/06/07
- Re: Question about memory management, David Chisnall, 2013/06/07
- Re: Question about memory management, Graham Lee, 2013/06/07
- Re: Question about memory management,
David Chisnall <=
- Re: Question about memory management, Maxthon Chan, 2013/06/07
- Re: Question about memory management, David Chisnall, 2013/06/07
- Re: Question about memory management, Maxthon Chan, 2013/06/07
- Re: Question about memory management, Ivan Vučica, 2013/06/07
- Re: Question about memory management, Maxthon Chan, 2013/06/07
- Re: Question about memory management, David Chisnall, 2013/06/07