Re: Intercepting retain/release of object
Re: Intercepting retain/release of object
- Subject: Re: Intercepting retain/release of object
- From: "Jonathan del Strother" <email@hidden>
- Date: Wed, 19 Mar 2008 18:04:24 +0000
On Wed, Mar 19, 2008 at 5:54 PM, Stuart Malin <email@hidden> wrote:
> I am having some trouble in an app with an object and its retain
> counts, so I added methods to intercept -retain and -release on my
> affected object so I could set breakpoints to observe the value. But
> doing so causes some really odd behavior, such as the object
> receiving extra retain events (such as when it is _removed_ from an
> array). Why would my intercepting these, but nonetheless propagating
> them up the class hierarchy, cause problems?
>
> - (void) retain
> {
> [super retain];
> unsigned int count = [self retainCount];
> NSLog(@"RETAIN: retain count after retain is: %i", count);
> }
>
> - (void) release
> {
> [super release];
> unsigned int count = [self retainCount];
> NSLog(@"RELEASE: retain count after release is: %i", count);
> }
>
-(id)retain needs to return itself, not void. And an object receiving
retain events on being removed from an array is quite possibly due to
NSArray putting your object into the autorelease pool, in which case
the pool will retain it for a short while.
Also, bear in mind that debugging via retainCounts is a surefire way to madness.
_______________________________________________
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