MemoryManagement

Crowd-sourced documentation and tutorials by the Cocoa developer community
Jump to: navigation, search


Memory Management Overview Page

MemoryManagement is a very central topic to programming. Many different systems for MemoryManagement have been devised, but since this is a Cocoa site, we can ignore most of them.

In Cocoa with Objective-C, MemoryManagement is handled by RetainingAndReleasing objects. Starting with Objective-C 2.0 and Mac OS X 10.5, and also when you are programming Cocoa with Java, you have the added option of using GarbageCollection.

The best thing you can do to learn memory management is to read the first two lines of RulesOfThumb. Then read them again.

ARC

Just to confuse things, in the most recent versions of Xcode (4.5 and higher), there is "ARC", or Automatic Reference Counting. For many programmers, this will vastly simplify everything, since to use it, you simply set the project to use it, and then get rid of all your retain, release, and autorelease calls. Dealloc's become mostly empty, most can go away.

Note that ARC might have an impact on performance compared to tight memory management. However, the vast majority of programs will not suffer. Release notes and documentation should be carefully studied before working around it.


CocoaDev articles dealing with MemoryManagement: [Topic]

Alloc+Init=New

External articles dealing with MemoryManagement


on optimizing Objective-C.


  • Non OS X, but some good background information on memory management principles:


  • Learning the basics of buffer overflows [1]
  • Self-manage data buffer memory [2]
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox