6

I was going through "Pro. Objective-C Design Patterns for iOS" by Chung and found

_sharedSinglton = [[super allocWithZone: NULL] init];

I looked in Apple's documentation for NSCopying as well, but can't really understand what a ZONE really means.

Monolo
  • 18,205
  • 17
  • 69
  • 103
Prashant Rane
  • 436
  • 4
  • 11

1 Answers1

7

NSZone is obsolete now, but back in the NEXTSTEP days, NSZone was an attempt to bring the concept of "malloc zones" into Cocoa. Here are some docs that described how it worked when it was enabled: http://www.cocoadev.com/index.pl?NSZone

StilesCrisis
  • 15,972
  • 4
  • 39
  • 62
  • so, how it's different to specify `zone` as `NULL` and `Default`? – Prashant Rane Jan 16 '12 at 08:25
  • 3
    I just looked up the book and quote on Google. I think the reason they use `-allocWithZone:` in this case is that their singleton pattern already overrode `-alloc`, and they wanted an easy way to avoid their `-alloc` override. `-allocWithZone:` dodges the override (since they never overrode that method) but doesn't change any behavior compared to a normal `-alloc` because zones are obsolete and don't do anything. Basically, this is a trick to dodge their own override of `-alloc` in an easy way, and the zone part is irrelevant. – StilesCrisis Jan 16 '12 at 17:02
  • thanks @StilesCrisis for the explanation; so, can we relate `Zone` as an `autorelease` pool (without autorelease functionality)? – Prashant Rane Jan 18 '12 at 04:50