Garbage collection from associative arrays

Sean Kelly sean at f4.ca
Sat Mar 25 11:05:43 PST 2006


Sebastian Beschke wrote:
> The following program creates a couple of instances of a class and
> stores them in an associative array. It then tries to periodically
> access those instances via the associative array, performing garbage
> collects in between.
> 
> As it appears, a fullCollect will destroy the objects, even though they
> are stored in an associative array. This leads to an access violation in
> the second loop.
> 
> Is this a known bug? Can it be fixed? Are there any workarounds?

I ran into something similar to this when first writing Ares, as I was 
using a map to store thread handles.  Basically, when a value is being 
added to the AA, the AA is first modified to hold some uninitialized 
data, then memory is allocated, then everything is initialized.  As it's 
possible this is the same problem, you may want to check out my fix here:

http://svn.dsource.org/projects/ares/trunk/src/dmdrt/aaA.d

Look for "better to fully construct" as a portion of the comment 
documenting the change.


Sean



More information about the Digitalmars-d-bugs mailing list