Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As of the latest iOS SDK, calling <code>[NSDate alloc]</code> always returns the same memory location. You can verify this behavior with the following code:</p> <pre><code>NSDate *date1, *date2; date1 = [NSDate alloc]; NSLog(@"date1: %p", date1); date1 = [date1 init]; NSLog(@"date1: %p", date1); date2 = [NSDate alloc]; NSLog(@"date2: %p", date2); date2 = [date2 init]; NSLog(@"date2: %p", date2); </code></pre> <p>I suspect that it has to do with the fact that <code>NSDate</code> is a <a href="https://developer.apple.com/library/ios/documentation/general/conceptual/CocoaEncyclopedia/ClassClusters/ClassClusters.html" rel="nofollow">class cluster</a>.</p> <p>If the private subclasses of a class cluster have different storage requirements, it's impossible to know inside of <code>alloc</code> how much memory to allocate. One approach to solving this problem, and it appears this is the approach that Apple is using with <code>NSDate</code>, is to let the <code>init</code> and factory methods handle all the memory allocation, since those methods know what private subclass is actually going to be used.</p> <p>At that point, all <code>alloc</code> is doing for you is allowing the user to preserve the <code>[[NSDate alloc] init]</code> pattern that's used for object creation everywhere in Objective-C. Since the memory location returned by <code>alloc</code> is always discarded, <code>alloc</code> may as well just return a fixed memory location, which is what it appears to be doing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload