Is GC smart enough not to reallocate?

MMJones via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 16 06:54:11 PDT 2016


Suppose one has something like

class foo
{
    int[] x;
    void bar()
    {
       x = [];
    }
}

Does the GC trash the "cache" when calling bar or does it realize 
that it can use the same memory for x and essentially just 
shortens the array?

Is it equivalent to setting length = 0?

I'm a bit worried that setting a managed array to [] might cause 
a completely new reallocation, which is unnecessary and 
undesirable.








More information about the Digitalmars-d mailing list