Smart pointers instead of GC?
Steven Schveighoffer
schveiguy at yahoo.com
Tue Feb 4 11:43:52 PST 2014
On Tue, 04 Feb 2014 14:31:13 -0500, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> On 2/4/14, 11:28 AM, Steven Schveighoffer wrote:
>> Where you have to be cognizant is avoiding cycles. Plain and simple. And
>> it's not that difficult.
>
> Do you have evidence to back that up?
Does personal experience count? I can say that the main project I have
worked on in Objective-C uses manual reference counting, and when I have
done newer, but shorter/smaller, projects in ARC, it is much much easier
to deal with. Maybe my point of reference is tainted :)
If you use xcode to add member variables, it usually chooses the correct
attributes for them (weak or not).
But the code the compiler generates for ARC is pretty good. It has quirky
rules for naming methods and how you have to return objects (either
autorelease or retained), and will not let you do the wrong thing. You
also can't do ANY manual memory management in ARC code, it fails to
compile.
Trickier aspects are dealing with C structs, which are NOT reference
counted, so you have to deal with those manually using malloc/free (not
really different from D).
I will say that it really helps to have an understanding of how ARC is
actually implemented in the compiler (that is, the process it goes through
to add/elide reference increments and decrements).
-Steve
More information about the Digitalmars-d
mailing list