Strong Variables

By default, all object pointer variables are strong variables. That means that assigning an object reference to such a variable causes that object to be automatically retained. Further, the old object reference will be released before the assignment is made. Finally, strong variables are initialized to zero by default. And that’s true whether it’s an instance variable or a local or global variable.

Look at this code, which creates and sets two Fraction objects.

Fraction *f1 = [[Fraction alloc] init];Fraction *f2 = [[Fraction alloc] init];[f1 setTo: 1 over: 2];[f2 setTo: 2 over: 3];

Now when you write the following using manual memory management

f2 = f1;

the effect is to just copy the reference to ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.