when is the object destuctor called?

Tony ignorethis at nowhere.com
Mon May 22 21:16:23 PDT 2006


"Johan Granberg" <lijat.meREM at OVEgmail.com> wrote in message 
news:e4sj2e$43o$1 at digitaldaemon.com...
>I came across this sentence in the specification
>
> "The garbage collector is not guaranteed to run the destructor for all 
> unreferenced objects."
>
> This made me wonder in what circumstances the destructor WONT bee called.
> Basically I want to do this: An object stores a OpenGL texture (uint) and 
> when the object gets collected/deleted I want to free the texture. I don't 
> care about if the destructor will bee called on program exit, but I need 
> some mechanism for freeing the textures during normal execution to prevent 
> a video memory leak.
>
> So I need to know if I can trust the destructor to do this or it their is 
> some other mechanism I can use.

Isn't this the type of problem the auto class was designed to address?

Of course, this does rely on matching the block structure of your 
application to the allocation/deallocation of resources.

It would be nice to have a more general mechanism than garbage collection, 
which allowed the programmer to register additional resources (other than 
memory) for automated management.


Tony
Melbourne, Australia 





More information about the Digitalmars-d mailing list