Re: Releasing Objects
Re: Releasing Objects
- Subject: Re: Releasing Objects
- From: mmalc Crawford <email@hidden>
- Date: Wed, 23 Dec 2009 09:36:47 -0800
On Dec 22, 2009, at 9:40 pm, Michael Craig wrote:
> At the point where the tutorial discusses garbage collection (end of ch. 5),
> I decided to implement the deallocation of the Converter objects created by
> ConverterController's convert: method. I want the deallocation to happen
> inside convert:. To test it, I'm using [converter retainCount], thinking
> that after the object is deallocated, that call will cause an error.
>
This is the wrong way to think about memory management.
You shouldn't be thinking in terms of deallocating another object, only in terms of ownership. You want to relinquish ownership of an object when you've finished with it. This is discussed in greater detail in <http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/20000043> and the memory management rules summarised in <http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994>.
To elaborate on bbum's messages, the documentation for retainCount is quite explicit...
<http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/retainCount>
mmalc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden