Does associative array change the location of values?

Steven Schveighoffer schveiguy at gmail.com
Sat Oct 30 17:45:57 UTC 2021


On 10/30/21 1:38 PM, Stanislav Blinov wrote:
> On Saturday, 30 October 2021 at 16:55:03 UTC, Steven Schveighoffer wrote:
> 
>> auto v = k in aa;
>> aa.remove(k);
>>
>> How can the GC/compiler work out that there is still a reference?
> 
> ??? The same way it does for all other references.
> 
> I think either you misunderstood me, or I misunderstood you.
> 

You said "deallocating unreferenced elements". I thought you meant 
elements unreferenced by the AA.

What I mean is, the AA isn't going to change implementations where it 
now deallocates values that may still have existing references. If 
that's the case, we can state that in the docs.

e.g.:

Removing a key does not deallocate the value that was removed. The 
value's lifetime is managed by the GC and will be alive until there are 
no references to that value.

-Steve


More information about the Digitalmars-d-learn mailing list