简体   繁体   中英

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

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.

在此处输入图片说明

在此处输入图片说明

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM