In this 3 cases I will have memory leak?
-
No __strong and no set to nil
- (void)function { NSString *string = [[NSString alloc] initWithString: @"Hello World"]; } -
No set to nil but use __strong
- (void)function { __strong NSString *string = [[NSString alloc] initWithString: @"Hello World"]; } -
No __strong but set nil
- (void)function { NSString *string = [[NSString alloc] initWithString: @"Hello World"]; string = nil; }
With Automatic Reference Counting (ARC), if I don’t set any keyword, I assume the variable is __strong?
If you don’t specify an ownership qualifier, it’s implicitly
__strong. Then, at the end of the local scope in which the variable is declared, the compiler inserts a release, regardless of whether you set the variable to nil.So, your local variable is released in all three cases — no leak.