THE AUTORELEASE ALTERNATIVE
If you’re responsible for the creation of an object and you’re going to pass it off to some other class for usage, you should autorelease the object before you send it off.
This is done with the autorelease method:
[objectautorelease];
You’ll typically send the autorelease message just before you return the object at the end of a method. After an object has been autoreleased, it’s watched over by a special NSAutoreleasePool. The object is kept alive for the scope of the method to which it’s been passed, and then the NSAutoreleasePool cleans it up.
-(NSString *)makeUserName
{
NSString *name = [[NSStringalloc] initWithString:@”new name”];
return [name autorelease];
}
如上例,返回的对象由NSAutoreleasePool负责释放,缺点是释放时刻不确定,没释放前占用系统的内存,调用者不用处理释放的问题,不过在使用retain方法时,必须调用配对的release,以平衡引用计数
使用UIKit库一个例子
UIButton *myButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
In most cases, the Cocoa Touch frameworks use a naming convention to help you decide when you need to release objects: If the method name starts with the word alloc, new, or copy, then you should call releasewhen you are finished with the object.
RETAINING AND COUNTING
What if you want to hold onto an object that has been passed to you and that will be autoreleased? In that case, you send it a retain message:
[object retain];
When you do this, you’re saying you want the object to stay around, but now you’ve become responsible for its memory as well: you must send a release message at some point to balance your retain.

▲
Event response
bare events (or actions)