There are a plenty of questions on SO regarding objective c
ARC
mechanism.
Many people asking if ARC
is going to replace GC
or not, etc. There are even discussions whether
it's reasonable to move to ARC
from GC
for Mac apps(if that does not require much work handling complex references in some data types, etc).
The obvious disadvantage of ARC
is complete lack of any mechanism for cleaning cyclic references (edit: cyclic strong references).
Here's a very good and simple explanation on memory leaks with ARC
What kind of leaks does automatic reference counting in Objective-C not prevent or minimize?
And interesting overview of advantages of apple's ARC
over their GC
.
http://lists.apple.com/archives/objc-language/2011/Jun/msg00013.html
I have a good understanding on how GC
works and what kind of problems it has,
but moving from C#/.NET
world to objective c / Cocoa
and reading stuff about ARC
I still cannot get one simple thing - why there is no background mechanism to clean cyclic references in ARC
application.
It does not require threads suspending, does it? So is relatively cheap to have. Is it a problem to implement one? An light version of GC which scans stack, registers, builds graph, finds cyclic references and frees memory without suspending application threads, sounds cool, no?
Does it require serious computation or other resources? It's hard for me to imagine how to find cyclic references without building all the object graph, but assuming this process is background and continuous it should be ok even in that way?
.NET 4.5 GC (http://blogs.msdn.com/b/dotnet/archive/2012/07/20/the-net-framework-4-5-includes-new-garbage-collector-enhancements-for-client-and-server-apps.aspx) has serious improvements in performance, but having cyclic references collector in ARC system will make second a winner? What are the next steps of ARC
system evolution? If it's possible and will sometime happen ARC
will have cyclic references collector, can it then fully replace GC
, or next gen GC
s (with even better performance) are going to eliminate ARC
systems?
UPD: Please do not post about weak
references, I know how to deal with cyclic references in ARC, and that's obvious, the question is about possibility to add cyclic references collector to existing ARC mechanism, as it would be as powerful and generic as modern GC are