On 31.05.2010 22:27, dave wrote:
I'm trying to figure out if a dynamically allocated memory in D is getting
collected with this simple test (using tango):

class Foo {
     ~this() {
         // destructor
     }
}

struct Item {
     Foo a;
}

Item[] items;
items.length = 1;
items[0] = Item();
items[0].a = new Foo();

items = null;

GC.collect();

I assume that calling GC.collect(); forces gc to go through and free up memory
for any unreferenced objects. It seems that the destructor for Foo isn't being
called. I'm not sure if the reference is still used somewhere or do I have to
explicitly call 'delete items[0].a' to ensure that the memory is freed?

I'm not sure why it doesn't work. But it's always better to post the code you're actually using, since now we can't be sure that you're not doing something else then what you think you're doing. If you know what I mean. :)

Reply via email to