@class Person;
@protocol PersonDelegate <NSObject>
- (void)sendLetterForPerson:(Person *)p;
@end
@interface Person : NSObject
@property (nonatomic, weak) id <PersonDelegate> delegate;
- (void)writeLetterComplete;
@end
@interface TestController ()<PersonDelegate>
@property (nonatomic, strong) Person *per;
@end
_per = [[Person alloc] init];
_per.delegate = self;
NSLog(@"%lu",(unsigned long)_per.retainCount);
NSLog(@"%lu",(unsigned long)_per.delegate.retainCount);
MRC create a Person object _per , set delegate , print retainCount . The _per.retainCount is one , but _per.delegate.retainCount is 12 ,why?
You should take a look at official document for
retainCount.I think it's not a problem if
_per.delegate.retainCountis 12._per.delegatehere is aTestController. MaybeviewControllerreferences are held by another objects which are designed by default system.For example, if
viewControlleris pushed with anUINavigationController,navigationControllerwill hold 1 reference toviewControllerand increaseretainCountby 1.