Custom delete not getting called

Ali Çehreli acehreli at yahoo.com
Fri Jun 24 23:01:36 PDT 2011


On Sat, 25 Jun 2011 09:23:19 +0530, d coder wrote:

> Hello People
> 
> I was just trying out custom memory allocation/deallocation that can be
> found on the link
> http://www.d-programming-language.org/memory.html#newdelete
> 
> The problem is that the delete function is never getting called. I have
> put an example test case at the end of the email.
> 
> Any ideas?
> 
> Regards
> - Puneet

There is no guarantee that if and when the destructor or the custom 
delete will be called on garbage collected objects. If they do get 
called, the call order is not deterministic.

You can define the objects as 'scope' to force their destructors to be 
called when exiting the scope:

> void main() {
>   for (size_t i = 0; i < 32; ++i) {
>     Foo foo = new Foo();

      scope Foo foo = new Foo();

>     write(foo.value);
>   }
> }

Ali


More information about the Digitalmars-d mailing list