ios - Which case should cause memory leaks? -


the code 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 four situations in code above, strong/weak, ivar/setter

which types cause memory leaks ?

which types same ?

i have test code nslog run (no nil printed) , why ? maybe autorelease ?

--------------edit---------------

i read document , find "string constant never deallocated"

so code act different when string initializes initwithstring or initwithformat (and code wrote wrong )

the weak property nil when using initwithformat

for memory management ivar , setter same: is self.ivar necessary strong properties arc?

if you're using arc system handles memory , won't report leak. here's writeup check out arc , difference between strong , weak references.

http://www.quora.com/objective-c-programming-language/in-objective-c-whats-the-difference-between-a-strong-and-weak-pointer


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -