- Objective-C Memory Management Essentials
- Gibson Tang Maxim Vasilkov
- 322字
- 2021-07-23 20:09:12
What is ARC and how does it work?
If you remember, the idea of reference counting covers the actual deletion of objects from the memory. With reference counting, Objective-C takes care of the actual object destruction. Owner objects are only responsible for releasing their claim of ownership on the object. So, logically the idea that appeared next was to make everything completely automatic as it was done in languages such as Java and C#. This idea was developed in the Garbage collection branch and Automatic Reference Counting.
Garbage collection is only available for Mac OS X, starting with version 10.5. Also, note that iOS applications can't use Garbage collection; since it relies on the power of the device, it will take some time to process, forcing the user to wait the process end, thus producing a bad user experience. It is also deprecated since OS X Version 10.8 is in favor of ARC and is scheduled to be removed in the forthcoming versions of OS X.
ARC is a new and innovative way that contains many of the Garbage collection's advantages, yet different from Garbage collection. ARC does not have any process in the background to make the object's deallocation, which gives ARC a big advantage against Garbage collection when comparing their performance.
However, before explaining how ARC does this, it's important to understand what ARC does not do:
- ARC does not impose a runtime memory model as Garbage collection does. Code compiled under ARC uses the same memory model as plain C or non-ARC Objective-C code, and can be linked to the same libraries.
- ARC only makes automatic memory management possible for Objective-C objects, inherited from
NSObject
(note that in Objective-C, blocks also happen to be objects under the covers though). - Memory allocated in any other way is not touched and must still be managed manually. The same goes for other resources such as file handles and sockets, such as streams.
- JSP網(wǎng)絡(luò)編程(學習筆記)
- Offer來了:Java面試核心知識點精講(原理篇)
- PyQt從入門到精通
- 從程序員到架構(gòu)師:大數(shù)據(jù)量、緩存、高并發(fā)、微服務(wù)、多團隊協(xié)同等核心場景實戰(zhàn)
- Functional Kotlin
- ASP.NET 3.5程序設(shè)計與項目實踐
- Responsive Web Design by Example
- Geospatial Development By Example with Python
- C指針原理揭秘:基于底層實現(xiàn)機制
- PyQt編程快速上手
- 零基礎(chǔ)C#學習筆記
- Greenplum構(gòu)建實時數(shù)據(jù)倉庫實踐
- Get Your Hands Dirty on Clean Architecture
- 你真的會寫代碼嗎
- Python GUI Programming Cookbook(Second Edition)