user387184
user387184

Reputation: 11053

Different memory management ARC / no ARC

I have to convert simple ARC code to non ARC. While it was relatively straight forward I missed an instance variable assignment self.var = xxx, instead I wrote var = xxx.

While in the ARC version it did not cause any trouble - in the non ARC version it certainly caused a crash.

Does that mean that it is actually OK to assign instance vars in ARC without the self. so they get retained?

Thanks!

ps what's the best source to learn how to program in ARC so one avoids abvious errors - so far I did not find any problem at all but I am getting nervous that I might have missed something

Upvotes: 2

Views: 1307

Answers (2)

Ankit Vyas
Ankit Vyas

Reputation: 7501

enter image description here

enter image description here

Automatic Reference Counting forbids explicit message send of ‘dealloc’

I have shared a trick to enable older library compilation in new iOS5 SDK.

Click on the Project.

Click on the target.

Select build phases tab.

Select the multiple files in which you want to turn off ARC.

Press ENTER / Hit Enter key

Type “-fno-objc-arc” ( without quotes, as shown in image )

Upvotes: 0

Kazuki Sakamoto
Kazuki Sakamoto

Reputation: 13999

Does that mean that it is actually OK to assign instance vars in ARC without the self. so they get retained?

Yes, kind of.

id obj_;

It is same as this.

id __strong obj_;

obj_ has strong reference for assigned object. The assigned object will not be dealloc-ed until the owner object for the ivar is dealloc-ed.

Please refer to LLVM document or the Apple's ARC reference that is still under NDA.

Upvotes: 1

Related Questions