Environment: OS X (10.6+)

Greetings:
   I've always thought to weak-link delegate methods to their hosts.  Hence the 
use of 'assign' vs 'retain' delegate assessors.
Quoting Apple's Delegate documentation:

"Delegating objects do not (and should not) retain their delegates. 
However, clients of delegating objects (applications, usually) are responsible 
for ensuring that their 
delegates are around to receive delegation messages. 
To do this, they may have to 'retain' the delegate in memory-managed code."

Source: 
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/CommunicatingWithObjects/CommunicateWithObjects.html


However upon viewing some code, I encountered a hard-link to a delegate (via 
'retain').

Scenario:   MyWindowController:NSWindowController ----->  
MyViewController:NSViewController (a delegate)



Inside 'MyViewController':

- (id)initWithSerial:(NSString *)_serial email:(NSString *)_email 
delegate:(NSObject <MyControllerProtocol>*)_delegate {
        self = [super init];
        serial = [_serial retain];
        email = [_email retain];
        //!!!: Delegating objects do not (and should not) retain their 
delegates. 
        // However, clients of delegating objects (applications, usually) are 
responsible for ensuring that their delegates are around to receive delegation 
messages.
        // Is 'MyController' a client of a delegating object?
        delegate = [_delegate retain];     // ...should this be 'retain' or 
'assign'?
        return self;
}

I'm a bit confused here.   On one hand, "...delegating objects should not 
retain their delegates."
... but on the other hand, "...clients of delegating objects...SHOULD retain 
their delegates."

Question: what is considered a 'client' of a delegating object?

In the above case, we have only a NSWindowController object and its 
NSViewController delegate.  
I don't see any client.  This is strictly a 1:1.

Any thoughts?

Regards,
Ric.

_______________________________________________

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

This email sent to arch...@mail-archive.com

Reply via email to