[Issue 2105] New: Manual Memory Management for Associative Arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 13 20:50:46 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2105

           Summary: Manual Memory Management for Associative Arrays
           Product: D
           Version: 2.013
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: dsimcha at yahoo.com


Due to the nature of conservative garbage collection, very large dynamic and
associative arrays are often not freed properly by the Phobos garbage
collector.  This is due to the high probability of a bit pattern on the stack,
when interpreted as a pointer, pointing to heap space occupied by these
structures.  In the case of dynamic arrays, this can be worked around by simply
deleting the very large array manually:

uint[] foo=new uint[100_000_000];
//stuff
delete foo;

However, if foo is an associative array, this cannot be done.

uint[string] foo;
//Put a large amount of data into array.
delete foo;  //Compile time error.

Furthermore, looping through such an array, such as:

foreach(i, bar; foo) {
    foo.remove(i);
}

fails to prevent memory leaks.  What is needed is a method of manually deleting
associative arrays that assumes that does not rely on the garbage collector.


-- 



More information about the Digitalmars-d-bugs mailing list