'delete' keyword

Jesse Phillips jessekphillips+D at gmail.com
Wed Jan 5 08:47:42 PST 2011


%u Wrote:

> Hi,
> 
> I just found out that the 'delete' keyword is intended to be deprecated, and I
> wanted to share several opinions about it and make a couple of suggestions:

Hey, I'm the one how started the other thread you saw. It was definitely not about whether delete should exist or not. I updated my answer on SO such that it is clearer how delete was replaced, though it still isn't something you should concern your self with most of the time.

"You don't. Delete is not to be used with D version 2 and intended to be removed from the language. What the hold up is, I am not sure. Instead you use a function, clear(object), which calls the destructor where you can free resources that are not GC memory. The distructor will be caused again during GC collection of the objects own memory. This is explained in "The D Programming Language".

"The idea is to reclaim resources earlier than what the GC would provide and prevents memory corruption from dangling pointers. To be less safe the core.memory module provides GC.free(object) which can be used to free the memory, after calling clear(object).

"As I'm not a C++ programmer, I don't really know the RAII pattern, but this and reference counting is the expected strategy if you wish to avoid the GC."

http://stackoverflow.com/questions/4589114/when-to-delete-in-d

Hope this would prevent fear of delete being removed.


More information about the Digitalmars-d mailing list