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
Nice. No more declaring interfaces simply to take advantage of the reference counting.
ReplyDeleteIt took a few years. Let's hope that it delivers!
ReplyDeleteSo, 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.
ReplyDeleteStefan Meisner Under ARC any cycles (cross referencing objects, graphs, parented trees, etc.) need special handling.
ReplyDeleteWeak 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).
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.
ReplyDeleteMust 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.
ReplyDeleteI'd rather have destructors (and copy constructors etc) for records than this.
Though I suppose it's needed on ARMy things like Android.
Asbjørn Heid Android apps typically use a GC rather than ARC.
ReplyDeleteEric Grange Ah thanks, I'm a bit of a luddite when it comes to these newfangled not-really-smart phones.
ReplyDeleteSo this ARC is just for iOS then?
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.
ReplyDeleteWhile 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).
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?
ReplyDeleteI 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...
Eric Grange ObjectiveC keeps reference counts in lists, Delphi doesn't. We are pretty sure our implementation is faster.
ReplyDeleteMarco Cantù If you don't keep a weak reference list, then how can you zero them?
ReplyDeleteARC is really nice. Wonder to see Delphi implementation.
ReplyDeleteEric 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+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