Aggregates & associations

Christopher Wright dhasenan at gmail.com
Wed Dec 19 14:24:08 PST 2007


Steven Schveighoffer wrote:
> "Sean Kelly" wrote
>> A long time ago Walter mentioned that the "scope" attribute may be extended 
>> to indicate aggregation:
>>
>>     class Foo
>>     {
>>         Bar valA;
>>         scope Baz val2;
>>     }
>>
>> With the above, the size of Foo would be expanded to contain an instance 
>> of Baz and val2 would be initialized to reference this memory, very much 
>> like "scope" works in functions now.  But I didn't see any mention of this 
>> in the D 2.0 writeup so the idea may have been either discarded or 
>> forgotten.
> 
> I believe this type of behavior is not necessary.  Whether a member is an 
> aggregate or an association, it will be deleted when nothing references it 
> anymore, which is when it should be deleted.  The only thing this proposed 
> behavior can do is cause segfaults when something that still has a reference 
> to a scoped member tries to use it.
> 
> -Steve 

I think the desired behavior is this:
1. Any object can have zero or one owners.
2. Any object that has an owner is collected and has its destructor 
called after its owner is collected and has its destructor called.
3. As an exception to (2), if an object's owner has no reference to it, 
the object can be collected.



More information about the Digitalmars-d mailing list