My app uses a Dictionary
protected _categoryToValueDict:Dictionary = new Dictionary();
to map something to something else.
Now, at a certain point in the application, I need to remove a certain key from the Dictionary
.
I implemented this simple method:
public function setCategoryNoValue( cat:TAModelCategory ):void {
// delete( _categoryToValueDict[ cat ] );
var old:Dictionary = _categoryToValueDict;
_categoryToValueDict = new Dictionary();
for ( var key:* in old ) {
if ( key != cat ) {
_categoryToValueDict[ key ] = old[ key ];
}
}
}
If I only use [description of the delete operator]
delete( _categoryToValueDict[ cat ] );
the app itself doesn't throw errors in normal mode. But as soon as I serialize its external data structure to an external source [currently SharedObject], the app isn't able to de-serialize it later on.
If I use the above coded manual iterative removal operation, the de-serialize operation works as expected and the model appears in the app.
The alternative should be identical. Shouldn't they?
Thus, my question: What's the difference between the two alternatives?
PS: This question might be related to my previous one.
UPDATE-1
Adobe explains on this page:
To make the object referenced by myObject eligible for garbage collection, you must remove all references to it. In this case, you must change the value of myObject and delete the myObject key from myMap, as shown in the following code:
myObject = null;
delete myMap[myObject];
Is suppose this to be a typo. Shouldn't it read like this:
delete myMap[myObject];
myObject = null;
Why pass a null-pointer to myMap as key?
Dictionary
? Also check the example prefixed by "The following example deletes the value of an array element, but the value of thelength
property is not changed" in the Adobe reference – Stutsman