Manual Deletion from Destructor

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Mar 14 11:24:59 PDT 2009


dsimcha wrote:
> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
>> You can't call delete against a struct object, so the above wouldn't
>> compile. What may solve your problem is calling GC.hasNoPointers against
>> the block of memory in which hugeDataStructure lives. But before that...
>> isn't the current GC non-conservative for heap-allocated objects? I
>> thought it's only conservative for stack objects.
>> Andrei
> 
> No, the problem is that there may be things that look like pointers pointing to
> internal regions of hugeDataStructure.  For example, let's say hugeDataStructure
> is a 100-megabyte array.  It's a pretty big target for false pointers, so even
> though the only legitimate reference is from the instance of Foo that owns it,
> hugeDataStructure might never get GC'd.  In my specific case, hugeDataStructure is
> a large associative array.  A few nodes don't get freed properly, leading to heap
> fragmentation and massive memory usage.  (I've created my own AA delete function,
> which I know works when not used from a destructor like the above example, see
> Bugzilla 2105).

Thanks for the info, that's very interesting.

Andrei



More information about the Digitalmars-d mailing list