Custom delete not getting called

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 25 06:20:20 PDT 2011


On 2011-06-24 23:01, Ali Çehreli wrote:
> 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);
> >   
> >   }
> > 
> > }

That version of scope is going away. Use std.typecons.scoped instead.

- Jonathan M Davis


More information about the Digitalmars-d mailing list