Skip navigation.
 
mlRe: Garbage collection - was Beginner with Cocoa
FROM : Erik Buck
DATE : Wed Mar 26 01:38:56 2008

We have been asked not to paraphrase or restate the memory management 
rules in this forum because slight inaccuracies, imprecisions, 
misstatements, or just idiocy confuses people.  Here is a quote:

From file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/chapter_3_section_5.html


If you create an object by allocating and initializing it (for 
example, [[MyClass alloc] init]), you own the object and are 
responsible for releasing it. This rule also applies if you use the 
NSObject convenience method new.
If you copy an object, you own the copied object and are responsible 
for releasing it.
If you retain an object, you have partial ownership of the object and 
must release it when you no longer need it.
Conversely,

If you receive an object from some other object, you do not own the 
object and should not release it. (There are a handful of exceptions 
to this rule, which are explicitly noted in the reference 
documentation.)
As with any set of rules, there are exceptions and “gotchas”:

If you create an object using a class factory method (such as the 
NSMutableArray arrayWithCapacity: method), assume that the object you 
receive has been autoreleased. You should not release the object 
yourself and should retain it if you want to keep it around.
To avoid cyclic references, a child object should never retain its 
parent. (A parent is the creator of the child or is an object holding 
the child as instance variable.)
Note: “Release” in the above guidelines means sending either a release 
message or an autorelease message to an object.

If you do not follow this ownership policy, two bad things are likely 
to happen in your Cocoa program. Because you did not release created, 
copied, or retained objects, your program is now leaking memory. Or 
your program crashes because you sent a message to an object that was 
deallocated out from under you. And here’s a further caveat: debugging 
these problems can be a time-consuming affair._______________________________________________

Cocoa-dev mailing list (<email_removed>)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>

This email sent to <email_removed>

Related mailsAuthorDate
mlBeginner with Cocoa Alex Handley Mar 21, 20:00
mlRe: Beginner with Cocoa Jeff LaMarche Mar 21, 20:21
mlRe: Beginner with Cocoa Jack Repenning Mar 24, 05:16
mlRe: Beginner with Cocoa Sherm Pendley Mar 24, 05:44
mlRe: Beginner with Cocoa Jeff LaMarche Mar 24, 13:12
mlRe: Beginner with Cocoa Erik Buck Mar 24, 15:13
mlRe: Beginner with Cocoa Scott Thompson Mar 24, 15:32
mlGarbage collection - was Beginner with Cocoa Bill Cheeseman Mar 24, 15:57
mlRe: Garbage collection - was Beginner with Cocoa colo Mar 24, 16:30
mlRe: Garbage collection - was Beginner with Cocoa Bill Cheeseman Mar 24, 17:12
mlRe: Garbage collection - was Beginner with Cocoa Erik Buck Mar 24, 17:12
mlRe: Garbage collection - was Beginner with Cocoa Clark Cox Mar 24, 17:45
mlRe: Beginner with Cocoa Jack Repenning Mar 24, 18:01
mlRe: Garbage collection - was Beginner with Cocoa colo Mar 24, 18:02
mlRe: Garbage collection - was Beginner with Cocoa Scott Thompson Mar 24, 18:36
mlRe: Beginner with Cocoa colo Mar 24, 18:43
mlRe: Garbage collection - was Beginner with Cocoa Bill Cheeseman Mar 24, 18:45
mlRe: Beginner with Cocoa Jeff LaMarche Mar 24, 18:54
mlRe: Beginner with Cocoa Sherm Pendley Mar 24, 18:57
mlRe: Beginner with Cocoa Chris Hanson Mar 24, 19:39
mlRe: Beginner with Cocoa Clark Cox Mar 24, 19:44
mlRe: Garbage collection - was Beginner with Cocoa colo Mar 24, 21:03
mlRe: Garbage collection - was Beginner with Cocoa has Mar 24, 22:59
mlRe: Garbage collection - was Beginner with Cocoa Scott Thompson Mar 25, 03:15
mlRe: Beginner with Cocoa Scott Ribe Mar 25, 21:57
mlRe: Garbage collection - was Beginner with Cocoa Scott Ribe Mar 25, 22:06
mlRe: Beginner with Cocoa Bill Cheeseman Mar 25, 22:40
mlRe: Garbage collection - was Beginner with Cocoa Jack Repenning Mar 25, 23:01
mlRe: Garbage collection - was Beginner with Cocoa Nick Zitzmann Mar 25, 23:07
mlRe: Garbage collection - was Beginner with Cocoa Paul Bruneau Mar 25, 23:11
mlRe: Garbage collection - was Beginner with Cocoa Randall Meadows Mar 25, 23:15
mlRe: Garbage collection - was Beginner with Cocoa Rob Napier Mar 26, 00:02
mlRe: Garbage collection - was Beginner with Cocoa Jack Repenning Mar 26, 00:28
mlRe: Garbage collection - was Beginner with Cocoa colo Mar 26, 00:52
mlRe: Garbage collection - was Beginner with Cocoa Erik Buck Mar 26, 01:38
mlRe: Garbage collection - was Beginner with Cocoa mmalc crawford Mar 26, 06:24