r/iOSProgramming • • Jul 12 '19

Article iOS Memory Management in Under 6 Minutes - Flawless iOS - Medium

https://medium.com/flawless-app-stories/ios-memory-management-in-under-6-minutes-3be777f69b7e
7 Upvotes

5 comments sorted by

18

u/antekm Jul 12 '19

It's not that great text to be honest. First of all it does explain ARC quite incorrectly - ARC is not compiler analysing all possible paths of code execution, but it's just counting references to some object and releasing them automatically when it goes down to zero. There's actually pretty simple logic behind it and the reason why it can't deal with cycles (if A has reference to B and B has reference to A the reference count will never go down to zero, even though both A and B are not accessible otherwise).

Also comparison with Garbage Collection is pretty poorly written. Yes, GC is not deterministic but it's not the only difference. GC will periodically analyse the whole graph of objects and will try to find objects that are no longer accessible from any known entry points and release them. This way it can handle cycles properly, but at the cost of being more expensive to run

2

u/[deleted] Jul 12 '19

Great input, hope the author gets this feedback so he/she can improve it.

-2

u/GenitalGestapo Jul 12 '19

It's not that great text to be honest. First of all it does explain ARC quite incorrectly - ARC is not compiler analysing all possible paths of code execution, but it's just counting references to some object and releasing them automatically when it goes down to zero. There's actually pretty simple logic behind it and the reason why it can't deal with cycles (if A has reference to B and B has reference to A the reference count will never go down to zero, even though both A and B are not accessible otherwise).

You're describing reference counting in general, not ARC. ARC does, in fact, analyze the usage of references to know when to inject retain and release calls, using a variety of heuristics. Then normal reference counting behavior takes over and objects are deinited when their reference count drops to zero. ARC makes no attempt to tackle the reference cycle issue.

3

u/antekm Jul 12 '19

I did simplify my remark as I didn't plan to write the whole article about it, but it's not working as described by OP anyhow.

9

u/[deleted] Jul 12 '19

Inaccurate and poorly written article. Don’t waste your time reading it.