ios - Why retainCount returns 2 -
this question has reply here:
when utilize -retaincount? 10 answers why retain count in negative value? [duplicate] 1 replyi have property:
@property(nonatomic, retain) nsmutablearray *myvar;
first case:
myvar = [[nsmutablearray alloc] init]; nslog(@retaincount: %i:", [myvar retaincount]);
outputs:
retaincount: 1
second case:
self.myvar = [[nsmutablearray alloc] init]; nslog(@retaincount: %i:", [self.myvar retaincount]);
outputs:
retaincount: 2
my question is: why in sec case retain value 2 ?
+1 because alloc/init
'd it +1 because self.myvar
retains (as set out in property declaration)
if autorelease
after alloc/init, go downwards 1... if set self.myvar
nil, nail 0 (if nil else has retained in meantime)
but vikingosegundo has said, don't want messing retain counts. os determines when knock them down, can't utilize them reliable measure of state.
ios objective-c cocoa-touch memory-management memory-leaks
No comments:
Post a Comment