Clarifcation on AA allocation
Walter Bright
newshound at digitalmars.com
Sat Apr 8 21:38:46 PDT 2006
pragma wrote:
> Is there any way to 'manually' allocate memory for an AA in D?
Not without reworking internal\aaA.d.
> The problem that prompted me to ask this? Well, I have a class that maintains a
> set of HANDLES using an AA. Ideally, I'd like to be able to free these using
> the class' dtor(), but isn't there the possibility that the GC will eliminate
> the AA's memory before the dtor() is even called?
As long as there's an active reference to the class object, anything the
class object references, including AA's, will not be free'd by the GC.
Once there is no longer an active reference to class object, then the
class object will be free'd along with any parts of the AA that are not
referenced elsewhere, however, the order in which the class object and
AA parts are free'd is undefined.
> I suppose I could instruct the GC to 'ignore' the AA via 'removeRange' for
> safety reasons, but I'd like to know if anyone else has a more elegant solution?
If you manually allocate/deallocate the class object, then manually
delete the class object (thereby invoking the class's ~this()), any
referenced AA objects will not have been collected already.
More information about the Digitalmars-d-learn
mailing list