> On 25 Jan 2017, at 16:48, Bill Cheeseman <[email protected]> wrote:
> 
> 
>> On Jan 25, 2017, at 11:23 AM, Dave <[email protected] 
>> <mailto:[email protected]>> 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.

Ok, I was looking in NSObject! 

Yes, I thought so, it occurred to me that I’ve seen instances where singletons 
override release so the (one) version of the object never gets release which is 
what I assume that document means by "your own reference-counting scheme”. I 
never implement singletons that way, preferring to use a factory class that 
allows N of each object to be created and just set N to 1.

All the Best
Dave


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to