- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_testObject = [[TestObject alloc] init];
NSLog(@"_testObject rc = %d", _testObject.retainCount);
NSLog(@"testObject rc = %d", self.testObject.retainCount);
}
And testObject is
@property (retain) TestObject *testObject;
Why is the output of these NSLog() 1 and 2, respectively? The retainCount of a property and the underlying object is different?
I’m guessing that it’s because your property isn’t defined as
nonatomic, so you’re getting a retained/autoreleased object. Try changing your property declaration to this: