Re: Overriding the release mehod
Re: Overriding the release mehod
- Subject: Re: Overriding the release mehod
- From: Bill Cheeseman <email@hidden>
- Date: Wed, 25 Jan 2017 11:48:52 -0500
> On Jan 25, 2017, at 11:23 AM, Dave <email@hidden> wrote:
>
> I hate it when people as that question! There are some memory leaks in a 3rd party package. It overrides release to unregister an observer but doesn’t call super. If I call super the leaks go away and all is well. I just want to know where is it documented really, I can’t find it searching the docs.
Look at Apple's Foundation NSObject protocol reference document for the -release method. It includes this statement:
"You would only implement this method to define your own reference-counting scheme. Such implementations should not invoke the inherited method; that is, they should not include a release message to super."
My framework does NOT define its own reference-counting scheme, within the meaning of that quotation. Instead, my framework overrides -release for the SOLE PURPOSE of unregistering an observer the last time a standard -release is called on the given object -- that is, when the separately maintained weakRetainCount reaches the specified value. In all other respects, my framework relies on the -release method to do what it always does.
Therefore, it IS in fact necessary to include [super release] at the end of the override.
--
Bill Cheeseman - email@hidden
_______________________________________________
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