Memory Management Rules

This document summarizes the rules for memory management in Objective-C.

This is the fundamental rule:

The following rules derive from the fundamental rule, or cope with edge cases:

The reasoning behind these rules is discussed in “Object Ownership and Disposal.”

Important: There are similar memory management rules for Core Foundation objects (see Memory Management Programming Guide for Core Foundation). The naming conventions for Cocoa and Core Foundation, however, are different. In particular, Core Foundation’s “create rule in Memory Management Programming Guide for Core Foundation” does not apply to methods that return Objective-C objects. For example, in the following code fragment, you are not responsible for relinquishing ownership of myInstance:

MyClass *myInstance = [MyClass createInstance];



© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-10-21)