Re: NSDictionary, allKeys and the NSAutoreleasePool
Re: NSDictionary, allKeys and the NSAutoreleasePool
- Subject: Re: NSDictionary, allKeys and the NSAutoreleasePool
- From: Graham Cox <email@hidden>
- Date: Fri, 4 Sep 2009 00:29:32 +1000
On 04/09/2009, at 12:21 AM, Horst Jäger wrote:
Any explanation?
Relying on retain counts to tell you an object's state is not a good
idea. What I'm guessing is that the code internally looks something
along the lines of:
- (void) release
{
if( retainCount == 1 )
[self dealloc];
else
--retainCount;
}
- (void) dealloc
{
mem_manager_put_on_free_list( self );
}
Nowhere is the retain count actually decremented to zero as it's just
a wasted operation. You hold a stale pointer to a freed object, so it
logs the stale retain count, which is 1. But sending it an actual
release is an error, as it's already been freed. No doubt this is one
of the many reasons why peeking at retain counts is widely discouraged.
--Graham
_______________________________________________
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