• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ARC and Singletons
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ARC and Singletons


  • Subject: Re: ARC and Singletons
  • From: Dave Zarzycki <email@hidden>
  • Date: Mon, 01 Aug 2011 09:17:24 -0700

On Aug 1, 2011, at 9:08 AM, Jeff Kelley wrote:

> Interesting. Your +setFoo: example, I’m assuming, sets a global int.

Correct.

> What about objects? I’m assuming that if I declare a global NSArray pointer like so:
>
> NSArray *foo = nil;

In general, globals default initialize to zero/nil/NULL and under ARC they must initialize to nil in order for ARC to work at all.

> and then have a +setFoo:(NSArray *)array method, that calling it with nil will be sufficient to clean up the array (that is, the ARC code will release the current array)?

Correct. Please be mindful of the fact that ARC does not magically fix concurrency issues (globals or otherwise).

davez


>
> Jeff Kelley
>
>
> On Mon, Aug 1, 2011 at 12:05 PM, Dave Zarzycki <email@hidden> wrote:
> The simplest and most ARC friendly way to implement the singleton pattern is to switch from instance methods to class methods – because the class itself is by definition a singleton. In other words:
>
>        + (MyClass *)sharedInstance;
>        // and maybe override alloc/retain/release to enforce the singleton pattern
>        - (int)foo;
>        - (void)setFoo:(int)val;
>
> …becomes simply:
>
>        + (int)foo;
>        + (void)setFoo:(int)val;
>
> davez
>
>
> On Aug 1, 2011, at 8:48 AM, Jeff Kelley wrote:
>
> > Is there a new recommended way to implement a singleton with ARC? I remember
> > hearing something about it, but I’m not sure what it was.
> >
> > Jeff Kelley

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >ARC and Singletons (From: Jeff Kelley <email@hidden>)
 >Re: ARC and Singletons (From: Dave Zarzycki <email@hidden>)
 >Re: ARC and Singletons (From: Jeff Kelley <email@hidden>)

  • Prev by Date: Re: ARC and Singletons
  • Next by Date: Re: Unnecessary Boolean Warning
  • Previous by thread: Re: ARC and Singletons
  • Next by thread: Re: ARC and Singletons
  • Index(es):
    • Date
    • Thread