the code is just simple:
@interface Test : NSObject
@property (nonatomic, strong) NSString * str; //strong
//@property (nonatomic, weak) NSString * str; //weak
-(void)func;
@end
@implementation Test
@synthesize str = _str;
-(void)func{
_str = @"test string"; // using ivar
//self.str = @"test string"; // using setter
}
@end
there are four
situations in the code above, strong/weak, ivar/setter
which types will cause memory leaks ?
which types are the same ?
I have test the code with NSLog but all run well (no nil printed) , why ? maybe about autorelease
?
--------------edit---------------
i read the document and find that "string constant would be never deallocated"
so the code act different when string initializes with initWithString or initWithFormat (and the code i wrote is wrong )
the weak property always be nil when using initWithFormat
for memory management ivar and setter are the same: Is self.iVar necessary for strong properties with ARC?