Reputation:
@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?
Upvotes: 0
Views: 144
Reputation: 12154
You should take a look at official document for retainCount
.
This method is of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method.
I think it's not a problem if _per.delegate.retainCount
is 12. _per.delegate
here is a TestController
. Maybe viewController
references are held by another objects which are designed by default system.
For example, if viewController
is pushed with an UINavigationController
, navigationController
will hold 1 reference to viewController
and increase retainCount
by 1.
Upvotes: 2