aa.remove in a destructor

Dmitry Olshansky dmitry.olsh at gmail.com
Sun Jun 24 00:53:37 PDT 2012


On 24-Jun-12 08:15, Ellery Newcomer wrote:
> this code:
>
> class X{
>      string[string] s;
>      this() {
>          s["s"] = "S";
>      }
>      ~this() {
>          s.remove("s");
>
>      }
> }
>
> void main() {
>      X x = new X();
> }
>
> produces this:
>
> core.exception.InvalidMemoryOperationError
>
> because the aa is calling gc_free during a collection, apparently.
>
> Should I be expecting the above code to run without error or not?
>
> thanks

I think no, as any with operation involving GC. For instance while you 
are removing elements table may decide to rehash itself and that means 
it may trigger allocation.

-- 
Dmitry Olshansky




More information about the Digitalmars-d-learn mailing list