0

Here is my code:

@interface YQViewController ()

@property (nonatomic, strong) UILabel *lb1;

@end

@implementation YQViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    self.title = @"title";

    self.lb1 = [[UILabel alloc]init];

    NSLog(@"retain count is %ld", CFGetRetainCount((__bridge CFTypeRef)self.lb1));

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

As you can see, I send +alloc and -init to self.lb1, I think the retain count of self.lb1 should equal 1, but the console output is 2. Can someone tell me the reason.(ARC enable, xcode 5, OSX 10.9.1, iOS 7 simulator).

billwang1990
  • 627
  • 2
  • 6
  • 16

1 Answers1

2

If you're looking up the value of retainCount, you're doing it wrong. There's no exception to that. You cannot rely on the resulting value to reflect what's going on in your code.

For full details, see http://whentouseretaincount.com

Tom Harrington
  • 62,792
  • 9
  • 129
  • 149