官术网_书友最值得收藏!

A brief history of reference counting

Before we get into the details of ARC, we need to rewind the time machine to a previous epoch. The year is 1988, and Objective-C is licensed by NeXT and starting to make its way into their operating system. In 1996, Apple acquires NeXT, alongside the release of OS X, a new and modern toolchain based on Objective-C. Objective-C is a strict superset of C, which means that any valid C code is valid Objective-C code, but unlike C, Objective-C has a modern and efficient memory management engine, based on reference counting.

Reference counting is a technique that accounts for the exact number of references to a particular object that exist at any given time in the memory. Once there are no references, an object, it is deallocated. This is a very different memory management technique, as compared to garbage collection, which you can find in Java or JavaScript.

Many benefits come with the use of reference counting. As there is no garbage collector, there is no need to freeze the process when the memory is cleaned up. It also provides benefits in performance and power management.

Let's go back to the pre-ARC era and write some Objective-C. Even if you're an avid Swift developer, understanding the origins of reference counting will help you to write more correct and efficient code.

Don't be afraid of Objective-C, even if the language is somehow verbose, with a lot of brackets; this is a very fun and performant language to work with.
主站蜘蛛池模板: 五常市| 南郑县| 昭平县| 榕江县| 宁津县| 阿城市| 阿克陶县| 海城市| 湾仔区| 光泽县| 新闻| 陇南市| 广汉市| 兖州市| 察雅县| 抚松县| 运城市| 黄陵县| 乡城县| 酒泉市| 洮南市| 自治县| 安泽县| 万荣县| 长宁县| 武城县| 咸丰县| 光山县| 文登市| 金沙县| 南靖县| 巴彦淖尔市| 房山区| 德庆县| 灵石县| 蕲春县| 高平市| 朝阳县| 兴化市| 聂荣县| 海淀区|