Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Memory management under ARC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 603
    Comment on it

    ARC Memory management

    1)Methods you cant call (or override) anymore

    You will have to remove all calls to these methods without substitution:

    1)retain

    2)retainCount

    3)release

    4)autorelease

    5)Dealloc

    You also cant use the retain keyword with properties anymore. Instead, use the strong keyword. Property naming restriction You can not create a property whose name begins with new.

    New Property keywords: strong and weak

    The @property keyword strong is synonymous to retain: earlier

    @property(retain) MyClass *myObject;

    now

    @property(strong) MyClass *myObject;

    Whereas weak is similar to assign, except that a weak property will be set to nil automatically when the object is deallocated (hence: zeroing weak reference): earlier @property(assign) MyClass *myObject; now @property(weak) MyClass *myObject;

    Under ARC, strong is the default for object types.

    Variable Qualifiers

    You use the following lifetime qualifiers for variables just like you would, say, const.

    __strong

    __weak

    __unsafe_unretained

    __autoreleasing

    __strong is the default. An object remains alive as long as there is a strong pointer to it.

    __weak specifies a reference that does not keep the referenced object alive. A weak reference is set to nil when there are no strong references to the object.

    __unsafe_unretained specifies a reference that does not keep the referenced object alive and is not set to nil when there are no strong references to the object. If the object it references is deallocated, the pointer is left dangling.

    __autoreleasing is used to denote arguments that are passed by reference (id *) and are autoreleased on return.

    Take care when using __weak variables on the stack. Consider the following example

    NSString * __weak string = [[NSString alloc] initWithFormat:@"First Name: %@", [self firstName]];

    NSLog(@"string: %@", string);

    Although string is used after the initial assignment, there is no other strong reference to the string object at the time of assignment; it is therefore immediately deallocated. The log statement shows that string has a null value

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: