> On 24 Aug 2016, at 1:24 pm, Andreas Falkenhahn <andr...@falkenhahn.com> wrote:
> 
> If it retains, I could just do the following:
> 
>    [textField setFormatter:formatter];
>    [formatter release];
> 
> And I wouldn't have to worry about "formatter" any longer. If it doesn't 
> retain,
> the above isn't possible. 

What actually happens inside -setFormatter: is not your concern. Maybe it 
retains the formatter; maybe it just copies some salient details out of it and 
lets it go. It makes no difference to you, the caller.

If you have no further use for the formatter, release it.

> Another example: "addSubview" retains, so I can just do:
> 
>    [[win contentView] addSubview:button];
>    [button release];
> 
> And I'm done with "button." That's much more convenient than having to
> keep "button" for much longer...

It certainly is. So release it. (The contentView has actually retained the 
button.)

> I still think I should know this so that I know when I should say
> "release" (see above)

You release when you, personally, are done with your object reference.

> So are you saying that the standard for setXXX methods is retain?
> And if a setXXX method doesn't retain, then it's explicitly mentioned
> in the doc?

Not necessarily, no! Maybe, for example, it copies? But it's an implementation 
detail.

If you want to make further reference to an object, you need to retain it in 
order to guarantee its lifecycle. Else, you can trust the API you're calling to 
retain things as it sees fit (unless some documentation advises you otherwise).

There is probably some Apple documentation that expresses the related concerns 
more clearly (or no doubt someone else on the list can be more eloquent). Here 
are a couple, although I recognize they speak more in terms of strong/weak 
references rather than philosophies related to scope of concern and manual 
reference-counting as you're concerned with targeting 10.6:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html#//apple_ref/doc/uid/TP40011210-CH5-SW3

https://developer.apple.com/library/mac/documentation/General/Conceptual/DevPedia-CocoaCore/ObjectOwnership.html#//apple_ref/doc/uid/TP40008195-CH67-SW1

-ben



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to