Τρίτη 24 Απριλίου 2012

Chapter 3 - ARC-autorelease-static analyzer


  • Objects never live inside one another: they exist separately on the heap. Instead, objects keep o references to other objects as needed. 
  • Instance variables live in the heap as part of an object.
  • Local variables live in the method's frame. 
  • Dealloc method, is sent to an object when it is about to be destroyed. 
  • A retain cycle occurs when two or more objects have strong references to each other. 
  • To fix the retain cycle use the parent-child relationship. The parent has strong reference to child, and the child has weak reference to the parent. (__weak)
  • An interesting property of weak references is that automatically sets the instance variable to nil. 
  • __unsafe_unretained attribut is not automatically set to nil when the object it points to is destroyed. It exists primarily for backwards compatibility: applications prior to iOS 5. 
  • nonatomic is not the default option, so you will always need to explicitly declare your properties to be nonatomic. 
  • if there is no instance variable that matches the name of a synthesized property, one is automatically created. 
  • when you have a property that points to an instance of a class that has a mutable subclass (like NSString or NSArray), it is safer to make a copy of the object to point to rather than pointing to an existing object that could have other owners. 
  • The copy method (of NSString) returns a new NSString object (not an NSMutableString).
  • Copy gives you a strong reference to the object pointed to. 
  • During the dark days of manual reference counting, Apple was contributing to an open source project known as the Clang static analyzer and integrating it into Xcode. Eventually, the static analyzer got so good that Apple thought, "Why not just let the static analyzer insert all of the retain and release message?" Thus, ARC was born. 
  • An autorelease pool is created by the @autoreleasepool directive followed by curly brackets. Inside those curly brackets, any newly instantiated object returned from a method that doesn't have alloc or copy in its name is placed in that autorelease pool. When the curly bracket closes, any object in the pool loses an owner. 
  • iOS application automatically create an autorelease pool for you, and you really don't have to concern yourself with it. 
#source: Big nerd ranch - iOS Programming 3rd Edition

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου