Derelict SFML destructor crashes

Jacob Carlborg doob at me.com
Mon Dec 17 01:52:07 PST 2012


On 2012-12-17 09:23, Jeremy DeHaan wrote:

> And how does calling destroy/delete in a struct destructor differ from
> doing the same in a class destructor? I too would like to make sure I am
> not getting any memory leaks!

Because there are guarantees how and when a destructor for a struct is 
called. You cannot rely on a destructor for a class when it's called, in 
what order they are called or if they're called at all.

import std.stdio;

struct Foo
{
     ~this () { writeln("destroying Foo"); }
}

class Bar
{
     ~this () { writeln("destroying Bar"); }
}

void foobar ()
{
     auto foo = Foo();
     auto bar = new Bar();
     // the destructor of "foo" _will always_ be called here
     // the destructor of "bar" _may_ be called here
}

void main ()
{
     foobar();
}

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list