www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Clarification on aa.remove(key)

reply Mike Parker <aldacron71 yahoo.com> writes:
According to the docs:

/ Particular keys in an associative array can be removed with the remove 
function:/

This says the key is removed, but says nothing about the value. Assuming 
the value is a class reference or a pointer, is it still referenced 
internally by the aa after the remove call or not? I don't want to leave 
any dangling references hanging around, so I need to know if we should 
be doing something like this:

aa[key] = null;
aa.remove(key);

If the value *is* no longer referenced, then perhaps the docs should be 
updated to read:

/ Particular key-value pairs in an associative array can be removed with 
the remove function:/
Jun 23 2005
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Mike Parker" <aldacron71 yahoo.com> wrote in message 
news:d9fql5$qgn$1 digitaldaemon.com...
 This says the key is removed, but says nothing about the value. Assuming 
 the value is a class reference or a pointer, is it still referenced 
 internally by the aa after the remove call or not? I don't want to leave 
 any dangling references hanging around, so I need to know if we should be 
 doing something like this:

I would assume the value is as well. It wouldn't make much sense for the key to be deleted and the value left, as they are in the same struct. I think the reference of "key" in the docs in this case refers to the "key-value pair" as you've pointed out.
Jun 24 2005
parent Mike Parker <aldacron71 yahoo.com> writes:
Jarrett Billingsley wrote:
 "Mike Parker" <aldacron71 yahoo.com> wrote in message 
 news:d9fql5$qgn$1 digitaldaemon.com...
 
This says the key is removed, but says nothing about the value. Assuming 
the value is a class reference or a pointer, is it still referenced 
internally by the aa after the remove call or not? I don't want to leave 
any dangling references hanging around, so I need to know if we should be 
doing something like this:

I would assume the value is as well. It wouldn't make much sense for the key to be deleted and the value left, as they are in the same struct. I think the reference of "key" in the docs in this case refers to the "key-value pair" as you've pointed out.

to. But no matter how senseless it would seem, and no matter how much I assume, the docs still say 'key' and not 'key-value pair'. I've been burned by little things like this before (not in D!), so just want it clarified.
Jun 24 2005