Blog post "Automatic Reference Counting for Delphi" at http://blog.marcocantu.com/blog/automatic_reference_counting_for_delphi.html

Blog post "Automatic Reference Counting for Delphi" at http://blog.marcocantu.com/blog/automatic_reference_counting_for_delphi.html

Comments

  1. Nice. No more declaring interfaces simply to take advantage of the reference counting.

    ReplyDelete
  2. It took a few years. Let's hope that it delivers!

    ReplyDelete
  3. So, bad but often seen techniques like casting an object to a Pointer etc. won't work any more? And objects, which reference each other will also not being destroyed automatically? I don't think I like the idea if it comes to cross platform as code, which has been developed with iOS and the new compiler in mind (and does not call Free) will leak when being compiled for windows.

    ReplyDelete
  4. Stefan Meisner Under ARC any cycles (cross referencing objects, graphs, parented trees, etc.) need special handling.
    Weak references can be used, but they have a high CPU overhead (they're maintained as lists under the hood) and have to be handled carefully in multi-threaded situations, so you probably don't want them anywhere near performance-critical code.
    Also be prepared to pepper "const" qualifiers for objects passed as parameters to minimize the reference-counting overhead (ie. same as for strings & interfaces currently).

    ReplyDelete
  5. It is a nice feature, but without the same for the Win part, it is a problem to use it in any Cross Platform way. It must be also in the Windows compiler.

    ReplyDelete
  6. Must admit I'm not too keen on this concept. If you switch between Windows and this ARM thing, it seems likely one might slip up and forget freeing on Windows.

    I'd rather have destructors (and copy constructors etc) for records than this.

    Though I suppose it's needed on ARMy things like Android.

    ReplyDelete
  7. Asbjørn Heid Android apps typically use a GC rather than ARC.

    ReplyDelete
  8. Eric Grange Ah thanks, I'm a bit of a luddite when it comes to these newfangled not-really-smart phones.

    So this ARC is just for iOS then?

    ReplyDelete
  9. Asbjørn Heid ARC can be used anywhere, but it's primarily used on iOS and by Apple. Google (Android & Chrome), Microsoft (.Net & WinRT) & Mozilla (FireFox OS) are going the GC route. C++ uses ARC, but only alongside a myriad other methods, and not as the only memory management.

    While ARC has the advantage of being deterministic, it has a not-so-insignificant reference counting overhead (especially on multi-core) and doesn't handle cycles very well (weak references are a kludge, requiring forethought, extra computational overhead, with poor multi-threading support).

    ReplyDelete
  10. Eric Grange Sorry I was unclear, I meant if EMB added ARC primarily because of iOS. As for C++ I suppose you're thinking of smart_ptr?

    I think the smart_ptr approach is fairly nice, as it's explicit when you use it. You can also easily get the raw pointer for when you need the speed within a well-defined scope.

    At least this ARC thing is deterministic, as you say. Can't reason about the GC...

    ReplyDelete
  11. Eric Grange ObjectiveC keeps reference counts in lists, Delphi doesn't. We are pretty sure our implementation is faster.

    ReplyDelete
  12. Marco Cantù If you don't keep a weak reference list, then how can you zero them?

    ReplyDelete
  13. ARC is really nice. Wonder to see Delphi implementation.

    ReplyDelete
  14. Eric Grange afaik, weak references are not automatically set to nil, you an check if they are still valid (but generally not required, if app logic and weak usage are correct)

    ReplyDelete
  15. +How can the validity check work without a list or a leak? Also won't that mean problems using non-delphi libraries or exposing Delphi libraries to other tools that expect the zeroing? (kinda like special behaviours made vcl.net "weird")

    ReplyDelete

Post a Comment