What is Automatic Reference Counting's impact on an arrow -> dereference?

40 Views Asked by At

If I say self->ivar = [[Foo alloc] init];, does ARC actually retain the new object? Or is this type of assignment used typically to prevent a retain?

1

There are 1 best solutions below

0
CRD On

does ARC actually retain the new object?

That depends on the attributes of ivar. If ivar has strong ownership qualification (the default for most variables) then the object will be retained.

It doesn't matter how the variable is found; whether it is a local, global, implicit instance (just the variable name), explicit instance (e.g. -> as in your sample), etc.; it only matters what the ownership qualifier on the variable is - ARC will do the right thing as indicated by the ownership qualifier.

HTH