Re: Intercepting retain/release of object
Re: Intercepting retain/release of object
- Subject: Re: Intercepting retain/release of object
- From: "Rob Napier" <email@hidden>
- Date: Wed, 19 Mar 2008 14:12:19 -0400
When you say "really odd behavior" can you confirm that you mean
"actually different from normal behavior" versus "not the behavior
your were expecting?" It does not surprise me that there may be a
retain involved during the removal of an object from an array. I would
expect it in order to manage KVO notifications which may fire after
the object is removed but before it is deallocated. Take a look at
your stack traces to see what is causing the retain.
Note that looking at retain counts can be tricky business, and they
are very often not what you might intuitively expect. Autorelease in
particular can lead to extra retains.
-Rob
On Wed, Mar 19, 2008 at 1: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);
> }
>
>
>
>
>
> _______________________________________________
>
> 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
>
--
Rob Napier -- Software and Security Consulting -- http://robnapier.net
"Those who would give up essential liberty to purchase a little
temporary safety, deserve neither liberty nor safety." -- B. Franklin,
Printer
_______________________________________________
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