Thu Rules of Cocoa Memory Management

   When you create an object using new, alloc, or copy, the object has a retain count of 1. You are responsible for sending the object a release or autorelease message when
you're done with it. That way, it gets cleaned up when its useful life is over.

   When you get hold of an object via any other mechanism, assume it has a retain count of 1 and that it has already been autoreleased. You don't need to do any further
work to make sure it gets cleaned up. If you're going to hang on to the object for any
length of time, retain it and make sure to release it when you're done.

   If you retain an object, you need to (eventually) release or autorelease it. Balance
these retains and releases.


That's it -- just three rules.

From: <<Learn Objective-C on the mac>>

你可能感兴趣的:(Thu Rules of Cocoa Memory Management)