delete and references?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Aug 8 09:45:37 PDT 2009


Michel Fortin wrote:
> On 2009-08-08 09:17:28 -0400, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> said:
> 
>> Great description.
>>
>> FWIW, I am trying to convince Walter to not reclaim memory in delete, 
>> but instead only call destructors. D continues C++'s mistake of 
>> conflating lifetime termination with memory reclamation.
> 
> I don't see how this changes anything. Instead of accessing a 
> deallocated object, you'll access a finaized but not yet deallocated 
> object. In both cases, it's a bug.

The former case has you using memory that was possibly allocated to an 
object of different type. This makes for intractable errors.

> Wouldn't it be better to have a system to track unique pointers? If you 
> knew that no other pointer points to a given object or memory block, you 
> can finalize and deallocate it safely. In fact, the current semantics of 
> a scope object assume that the programmer will not leave any dangling 
> pointers at the end of the scope, so it's already assuming uniqueness, 
> just not enforcing it.

Unique pops in an out as a topic for future directions. It is quite 
difficult to make it at the same time correct, inconspicuous, and 
useful. We have firmly decided to do away with unique for D2.


Andrei



More information about the Digitalmars-d mailing list