Suppose I have a view controller like this:
@interface ControllerA : viewcontroller{
NSString * __strong a;
}
@end
and in viewDidLoad
function I set
a = [[NSSString alloc] init];
And in another ControllerB,
{
ControllerA * controllerA = [[ControllerA alloc] init];
}
Will controllerA's member be released?
Yes, the string pointed to by a
will be released when controllerA
is deallocated. You don't need to set it to nil
yourself.
Transitioning to ARC Release Notes is currently the place to look for more information about working with ARC. One important point that it makes is that you may still need a custom -dealloc
if your class needs to do anything other than releasing instance variables when it's instances are deallocated.
You never need to set a variable to nil in ARC unless you want to ensure its deallocation as soon as possible (i.e. [myObject release] under non-ARC code). All iVars will be automatically released when the object is deallocated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With