Clarifcation on AA allocation

kris foo at bar.com
Sat Apr 8 14:48:17 PDT 2006


pragma wrote:
> Is there any way to 'manually' allocate memory for an AA in 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?

That's right. You cannot rely on any related GC-managed memory to be 
intact when a dtor is invoked. As Sean noted, D "death tractors" are 
akin to finalizers elsewhere.

> 
> 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?

Or malloc() them into your own list, and use the AA simply as an 'alias' 
of sorts?

Are instances of this class intended to be long-lived? Singleton, perhaps?



More information about the Digitalmars-d-learn mailing list