1. Ownership
    1. You own any object you create
    2. You can take ownership of an object using retain
    3. You must relinquish ownership of objects you own when you’re finished with them
    4. You must not relinquish ownership of an object you do not own
  2. Alloc
    1. 便利寫法
      1. NSNumber *zero = [NSNumber numberWithInteger:0];
      2. 會Autorelease
    2. 標準寫法
      1. NSNumber *zero = [[NSNumber alloc] initWithInteger:0];
      2. 需要自己release
  3. Copy
    1. Copy non-pointer iVar
      1. Deep copy only
      2. int a = b;
    2. Copy pointer iVar
      1. Deep Copy
        1. Copy the data
        2. Element *a = [b copy];
      2. Shallow Copy
        1. Copy the pointer
        2. Element *a = b;
    3. Array
      1. Add to an Array means "Copy"
      2. Remove from an Array means "Release"
      3. objectAtIndex only get the pointer
  4. Reference
    1. Strong reference
      1. Retain
        1. Object will be dealloc if ALL the strong references are released
        2. Retain is preventing object from being released
    2. Weak reference
      1. table data sources
      2. outline view items
      3. notification observers
      4. delegates
  5. Release
    1. Autorelease
      1. Every thread needs its own autorelease pool
      2. To clean the autorelease pool, use "drain" is better than use "release", drain will trigger garbage collection in some case
    2. Manual release
  6. Accessor Methods
    1. Why use it? Just better, clear and avoid bugs
    2. How
      1. 分支主題 2
        1. Retain
          1. Retain and autorelease the value before return return [[title retain] autorelease];
          2. Release the old value and retain new value if (title != newTitle) { [title release]; title = [newTitle retain]; // or copy depending on your needs }
        2. Assign
          1. Return the value return title;
          2. Autorelease old value and retain the new value [title autorelease]; title = [newTitle retain];
        3. Assign
          1. Return the value return title;
          2. Release the old value and retain new value if (title != newTitle) { [title release]; title = [newTitle retain]; // or copy depending on your needs }
        4. Copy
          1. - (NSString *)name { return [[name copy] autorelease]; }
          2. - (void)setName:(NSString *)aName { [name autorelease]; name = [aName copy]; }
  7. Object in Nib file
    1. Retain and Autorelease
    2. DidReceiveMemoryWarning
      1. [self setView:nil];
      2. - (void)viewDidUnload { self.anOutlet = nil; [super viewDidUnload]; }