0

Coming from .NET (C#) development to do a bit of Objective-C coding, I have stumbled upon ARC (Automatic Reference Counting).

I know that C++ (and probably Objective-C) have deterministic destruction semantics, and ARC seems to be another step in the same direction.

While I am not familiar with the internals of it, I was wondering (at the theoretic level) whether an ARC equivalent could have been retrofitted on top of .NET (that uses a GC).

lysergic-acid
  • 19,570
  • 21
  • 109
  • 218
  • 5
    Why would you *want* to? What purpose is there in using two entirely different approaches to solving the same problem? – Servy Dec 17 '14 at 21:11
  • Theoretically, yes, but it'd be pointless - the .NET runtime already runs the GC to clean up unused object instances. Adding ref counting on top of that (while possible) would simply force the programmer to do more work for no gain. It'd also be error prone - the major issue with ref counting is that if you forget to release something, it'll sit around forever in memory. – xxbbcc Dec 17 '14 at 21:15
  • 1
    @xxbbcc one can design a language that counts references for you, as an alternate method for managing memory to the .NET GC style of memory management. It wouldn't need to involve any more work from the programmer. – Servy Dec 17 '14 at 21:18
  • @Servy yes, I realized I missed the 'automatic' part of ARC after posting the comment - my comment was based on manual reference counting. – xxbbcc Dec 17 '14 at 21:20

1 Answers1

1

Actually, there are some refcounting. COM and RCW interop (more info here) and Safe handles for example.

However, there's no reference-counted objects to be used explicitly. And to be honest, you almost never will be cared about refcounting under the cover, at least until it works:)

P.S. If you're interested in "why not?" reasons, here's the answer.

Community
  • 1
  • 1
Sinix
  • 1,306
  • 9
  • 46