2013年7月20日星期六

IOS OC reference counting memory management issues

The newly created object reference count should be a right, but why is not this
XCode 4.6.2
#import int main(int argc, const char * argv[]) { @autoreleasepool { NSSet * set = [[NSSet alloc] init]; NSLog(@"NSSet retainCount : %zi", set.retainCount); [set release]; NSString *string = [[NSString alloc] init]; NSLog(@"NSString retainCount : %zi", string.retainCount); [string release]; NSArray *array = [[NSArray alloc] init]; NSLog(@"NSArray retainCount : %zi", array.retainCount); NSMutableArray *mutableArray = [[NSMutableArray alloc] init]; NSLog(@"mutableArray retainCount : %zi", mutableArray.retainCount); [mutableArray release]; } return 0; }

< >

------ Solutions ----------------------------------- --------------------- < >
Typically there should be no reason to explicitly ask an object what its retain count is (see retainCount). The result is often misleading, as you may be unaware of what framework objects have retained an object in which you are interested. In debugging memory management issues, you should be concerned only with ensuring that your code adheres to the ownership rules.
Original: http://stackoverflow.com/questions/2640568/objectivec-how-to-get-the-reference-count-of-an-nsobject

没有评论:

发表评论