ARC + loopback versus leading edge GC (say .NET 4.5 GC)

There are many questions in SO regarding the objective c mechanism objective c ARC . Many people ask if ARC replace GC or not, etc. There is even discussion of whether it is wise to switch to ARC from GC for Mac applications (if it does not require a lot of processing complex links in some data types, etc.).

The obvious drawback of ARC is the complete absence of any mechanism for clearing circular links (edit: circular strong links). Here's a very good and simple explanation of memory leaks using ARC What leaks does automatic reference counting in Objective-C not prevent or minimize?

And an interesting overview of the benefits of apple ARC over their GC . http://lists.apple.com/archives/objc-language/2011/Jun/msg00013.html

I understand how GC works and what problems it has, but moving from the C#/.NET world to objective c / Cocoa and reading material about ARC , I still can’t get one simple thing - why is there no background for cleaning cyclic links in the ARC application .

It does not require a suspension of threads, does it? So it's relatively cheap. Is this a problem to implement? A lightweight version of GC that scans the stack, registers, plots, finds circular references and frees memory without pausing applications, sounds cool, no?

Are serious calculations or other resources required? It’s hard for me to imagine how to find circular references without building all the graphs of objects, but assuming that this process is background and continuous, it should be fine even in this 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 major performance improvements, but will having a circular set of links in the ARC system make the second winner? What are the next steps in the evolution of the ARC system? If this is possible and will ever happen, will ARC have a collection of circular references, can it completely replace GC , or is the next GC gene (with even greater performance) going to eliminate ARC systems?

UPD: Please do not publish links to weak , I know how to handle circular links in ARC, and this is obvious, the question is whether it is possible to add a circular link collector to an existing ARC mechanism, since it would be as powerful and universal as modern gc

+4
source share
2 answers

C-based world loop detection requires one of two things:

  • all assignments of objects everywhere always pass through the write barrier (and, possibly, the read barrier, depending on the characteristics of the collector)

  • the scanner must “stop the world” in order to keep memory in a consistent state when scanning cycles

The first is a single memory model and carries massive overhead compared to direct C (but may be more efficient than pure manual save / release). In practice, you usually “avoid” objects from the barrier world to non-barrier locations using some kind of manual reference counting (which is pretty much identical to the bridge mechanisms in the ARC compiler; CFBridgingRetain (), etc ...)

The latter is much easier for the developer, but makes the performance completely unpredictable, since you can never know when or for how long any thread will be stopped. Without barriers, you cannot stop only one thread at a time.

Both of them add significant overhead compared to the relative "metal" nature of the C-based environment. In a VM-based environment, the cost is largely eliminated by combining virtualization of the connectivity of the object graph in conjunction with the implementation of JIT after compilation, which provides optimization that far exceeds the capabilities which are possible in a precompiled environment such as C (precompiled, static executables ... not the precompiler itself).

+8
source

Your question should have been: What is the mechanism for resolving cyclic reference problems in ARC?

And to that, the answer is: Weak pointers.

0
source

All Articles