J,
Well, it's not really written on a tablet or anything, but removeMediator isn't really that often used. But when you need to use it, you need to use it.
So, I'm having a look at your suggestion. The following:
//
// !!!! remove the key from the map
//
delete observerMap[ notificationName ];
is really not doing anything beyond the
observerMap[ notificationName ] = null;
that precedes it.
From Programming ActionScript 3.0 > Core ActionScript 3.0 Data Types and Classes > Working with Arrays
You may come across code that uses the delete operator on an array element. The delete operator sets the value of an array element to undefined, but it does not remove the element from the array.
The problem boils down to there being no proper way to remove a key from an
associative array, you can only set its value to null. Short of copying the array element by element, leaving out the keys with null values, and replacing it. I'm still not sure I want to do that here. Primarily because I don't think it would be performant in those use cases which do drive us to use removeMediator a lot.
It is a trade off between a squeeky clean memory profile (where we remove every key in every map leading to zero build up) AND performance when we are adding and removingMediators a lot. Those keys are tiny and shouldn't ever really cause a problem it's the objects they point to that we're really worried about tossing to the GC.
I believe that that we will likely find that adding the
if(observers != null)
check will suffice, but I don't want to do it hastily. A soon as I can, I'll pound on this and arrive at a conclusion and likely a 1.6 maintenance release.
Thanks much for your input on this, I really appreciate it.
-=Cliff>