"In general, however, you should try to avoid using
autorelease
wherever possible as it’s a more resource intensive operation than release
."Apple recommends that iPhone programmers follow these memory management guidelines:
To make sure it is clear when you own an object and when you do not, and what responsibilities you have as an owner, Cocoa sets the following policy:
You own any object you create.
You “create” an object using a method whose name begins with “alloc” or “new” or contains “copy” (for example,
alloc
,newObject
, ormutableCopy
).If you own an object, you are responsible for relinquishing ownership when you have finished with it.
You relinquish ownership of an object by sending it a
release
message or anautorelease
message (autorelease is discussed in more detail in “Delayed Release”). In Cocoa terminology, relinquishing ownership of an object is typically referred to as “releasing” an object.If you do not own an object, you must not release it.
This policy applies both to GUI-based Cocoa applications and to command-line Foundation tools.
The entire documentation can be found here:http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html#//apple_ref/doc/uid/10000011
No comments:
Post a Comment