I may have found a bug.

Jeremy DeHaan dehaan.jeremiah at gmail.com
Wed May 29 00:32:39 PDT 2013


Hey guys,

I believe I found a bug with Associative Arrays, and I want to 
make a bug report, but I am not sure what severity to place this 
under, or perhaps I am doing something wrong.


Here is what happens: If a class has a static Associative Array 
member, calling remove in the destructor will cause a invalid 
memory operation error if it is during a GC cycle(or at least at 
the end of the program). If the object is manually destroyed I 
get no such error. Also, if the Associative Array isn't a static 
member of the class and instead is a module scope variable, the 
error doesn't appear anymore.

I made a minimal example to show what I mean.

module main;

import std.conv;
import std.stdio;

void main(string[] args)
{
    AssocArrayTest test1 = new AssocArrayTest();

    //destroy(test1);
}


class AssocArrayTest
{
     private static string[uint] ClassNames;
     private static uint ClassIDCounter = 0;

     private uint ID;
     this()
     {
         ID = ClassIDCounter++;
         ClassNames[ID] = "AssocArrayTest " ~ text(ID);
         writeln(ClassNames[ID]);
     }

     ~this()
     {
         ClassNames.remove(ID);
     }
}


Thoughts?


More information about the Digitalmars-d mailing list