iOS Reference Library Apple Developer
Search

Memory Management Rules

This article 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];
See also “Memory Management of Core Foundation Objects in Cocoa.”




Last updated: 2010-06-24

Did this document help you? Yes It's good, but... Not helpful...