Manual memory management in D2

Vladimir Panteleev vladimir at thecybershadow.net
Sun Jul 11 13:00:15 PDT 2010


On Sun, 11 Jul 2010 21:29:40 +0300, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Simen kjaeraas:
>
>> Petr:
>>> What would happen if i skipped clear()?
>>
>> Then your destructors wouldn't get called. GC.free takes a humble void
>> pointer, which knows little of destructors and other such fancy things.
>>
>> If you feel unsure you will remember, feel free to use this function:
>>
>> void destroy( T )( T obj ) if ( is( T == class ) ) {
>>      clear( obj );
>>      GC.free( obj );
>> }
>
> That can be a good thing to add to Phobos2 or the core. An overloaded  
> version with the same name for nonclasses can be added.

Can someone please explain to me how this is different and *better* than  
the allegedly now-deprecated delete statement?

Also, what happens if the object instance was allocated on the stack?

-- 
Best regards,
  Vladimir                            mailto:vladimir at thecybershadow.net


More information about the Digitalmars-d mailing list