I know that how ARC and MRC works. but I am confuse while testing the below code. I don't know why this happen. Why the retain count is different in debug mode and in running mode for the same question?
NSMutableArray *a = [NSMutableArray array];
[a addObject:@"abc"];
NSLog(@" 1 Retain count is %ld", CFGetRetainCount((__bridge CFTypeRef)a));
__weak NSMutableArray *b = a;
NSLog(@" 2 Retain count is %ld", CFGetRetainCount((__bridge CFTypeRef)a));
a = nil;
NSLog(@" 3 Retain count is %ld", CFGetRetainCount((__bridge CFTypeRef)b));
[b addObject:@"xys"];
NSLog(@" 4 Retain count is %ld", CFGetRetainCount((__bridge CFTypeRef)b));
When I run the app in running mode the app crash on line NSLog(@" 3 Retain count is %ld", CFGetRetainCount((__bridge CFTypeRef)b));
that I understand as the b is weak
reference of a. and object a get release when assign nil
to it. but before that if shows the out put of first two line as the the below image. Which is also correct.
But When the app is debug mode (Means we have set break point and debug) then the app didn't crash and also show retain count 2 on each line. as the below image.
Does any one having idea why this happen? Why the same code gives two different retain value for different mode?