The reference-counted memory management system

Cocoa use a counter, the retainCount to know when an object must be deallocated.

When an object is initialized, its retainCount value is set to one, meaning "I am used at one place".

During it's life, this object may encounter several call to retain or release.

When retain is called, the retainCount value is incremented, meaning "I am used at one more place". Inversely, when release is called, the retainCount value is decremented. When the counter value reaches zero, the object is deallocated.

The autorelease method is a variant to the simple release one. When an object receive this message, it adds itself to the nearest autoreleasepool. When this pool is released or train, all objects that were put in it receive a release message.

You can create your own autoreleasepool, sometimes you must do it. There exist at least one pool in your program, located in the event loop.