DIP60: @nogc attribute

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 17 22:53:00 PDT 2014


On 4/17/2014 6:58 PM, Michel Fortin wrote:
> Auto-nulling weak references are perfectly memory-safe. In Objective-C you use
> the __weak pointer modifier for that. If you don't want it to be auto-nulling,
> use __unsafe_unretained instead to get a raw pointer. In general, seeing
> __unsafe_unretained in the code is a red flag however. You'd better know what
> you're doing.
>
> If you could transpose the concept to D, __weak would be allowed in @safe
> functions while __unsafe_unretained would not. And thus memory-safety is preserved.

I recall our email discussion about implementing ARC in D that we couldn't even 
avoid an inc/dec for the 'this' when calling member functions. So I don't see 
how inc/dec can be elided in sufficient numbers to make ARC performant and 
unbloated.

Of course, you can always *manually* elide these things, but then if you make a 
mistake, then you've got a leak and memory corruption.


More information about the Digitalmars-d mailing list