[Dlang-study] [lifetime] Initial thoughts on lifetime management

Jacob Carlborg doob at me.com
Wed Oct 28 00:44:51 PDT 2015


On Wednesday, 28 October 2015 at 00:45:00 UTC, Andrei 
Alexandrescu wrote:
> Hello all and thanks for your interest in the topic of lifetime 
> management of D objects. This post outlines a starting point 
> for the discussion.

I would like to mention a previous email conversation that has 
already been posted on the newsgroups for reference [1]

> Here there are two options we discussed - an @rc attribute, or 
> simple detection of a pair such as opInc/opDec. I've argued for 
> the latter but Walter made a good argument for @rc: it gives 
> the compiler complete control over "as-if" style optimizations. 
> So I'll proceed under the assumption that we go with @rc. 
> Namely, we're looking at:
>
> @rc class Widget {
>     ...
> }

Are there plans to allow the implementor of a @rc class to decide 
the implementation of the reference counting? I'm thinking from 
the point of view of Objective-C interoperability.

> Such classes:
>
> * do not inherit Object. (Do we want a root of all @rc classes 
> called RCObject?)

Not sure if this has any implications for the Objective-C 
interoperability. In Objective-C there's one root (kind of), that 
is "NSObject". Not sure if there would be a problem if NSObject 
in D inherited from RCObject.

> * cannot be converted to interfaces (we may later add @rc 
> interfaces)

I'm pretty sure this will be needed when proper support for 
Objective-C interface are added.

> * embed an implementation-defined reference count as a hidden 
> member

I guess this answers my first question.

All the concerns mentioned above about Objective-C 
interoperability can of course be special cased in the compiler, 
if needed.

[1] http://forum.dlang.org/thread/l34lei$255v$1@digitalmars.com

--
/Jacob Carlborg


More information about the Dlang-study mailing list