Is an OOP version of C using message passing. Uses a variation of GCC and GDB Has dynamic and static memory allocation Uses “Reference Counting” to manage memory in iOS.
owner Object’s creator becomes its 1st owner Other owners must retain object Owner is responsible for releasing object Owner must never destroy object directly Object without owners are deallocated automatically Weak references used to avoid infinite retain loops
withObject:nil]; } -(void)play { // without pool every autoreleased object will leak memory NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; // safe accessor returns autoreleased object, added to thread’s autorelease pool NSArray* petsToPlay = [self pets] ; BOOL allPetsAreHappy = NO; while(! allPetsAreHappy) { ... // some code, that may create autoreleased objects } [pool release]; // or [pool drain]; memory is freed, petsToPlay released as well } @end
owner of it, use a method that has one of these in its name: - alloc - new - copy - mutableCopy If we use properties and convenience constructors we do not take ownership of the object. - Convenience Constructors (Factory Pattern) like: stringWithFormat, imageWithData, imageWithContentsOfFile, stringWithContentsOfFile
the retain are greater than the releases or A dangling pointer, if the releases are greater than the retains. (Bad Access Error or accessing an illegal piece of memory)