Do AAs allocate on removal?
    Gerrit Wichert 
    gwichert at yahoo.com
       
    Sat Dec  7 11:04:03 PST 2013
    
    
  
Am 07.12.2013 19:07, schrieb thedeemon:
>
> A quick glance into the source shows that removing an entry does not 
> allocate, but calls GC.free(). Inserting an entry does allocate. 
> Rehashing happens when entries are added, not when they are removed.
>
> Check your destructors again, make sure they are not called twice.
>
Thanks for your quick answer. So the call to GC.free() breaks it. Seems 
easy to fix, just don't free and let the GC do its work. Whatever, I've 
solved my problems by nulling out the value and calling a cleanup 
routine before the next entry is added.
         private static void cleanObjects()
         {
             if (shouldCleanObjects) {
                 foreach (key, val; objects) {
                     if (!val) {
                     objects.remove( key);
                 }
             }
             shouldCleanObjects = false;
           }
         }
  Seems to work, but I'm not shure if it is save to remove entrys while 
iterating. Can't find any advise at this.
Gerrit Wichert
    
    
More information about the Digitalmars-d
mailing list