Deterministic resource freeing - delete deprecation (again)

Daniel Gibson metalcaedes at gmail.com
Wed Apr 27 06:44:29 PDT 2011


Am 27.04.2011 15:37, schrieb Alexander:
> On 27.04.2011 15:15, Steven Schveighoffer wrote:
>
>> You can use clear to call the destructor of a class, and then GC.free (if you wish) to free the memory.
>
>    BTW, why it is called clear()? To me, clearing something is not destruction. For instance, some buffer object may be cleared to empty the buffer, so the action of clear() is counter-intuitive, IMHO.
>
> /Alexander

clear() also works for simple types and pointers - it just resets them 
to type.init.
Which sucks when it's a pointer to a struct and the pointer is set to 
null instead of calling the structs destructor.

Maybe a function called "destroy()" that only works for classes and 
structs (with destructors? or just null other kinds of structs or 
something?) may help. It's a better name and it could work more like 
you'd expect for pointers to structs.


Cheers,
- Daniel


More information about the Digitalmars-d mailing list