AS3 - Dictionary objects allocated by a simple dictionary[key]=value call

267 Views Asked by At

While profiling my app in Scout I noticed it shows that the method JSONObject.internalPut is responsible for allocating 2,355 Dictionary objects.

The method's code is as follows:

internal function internalPut(key:String, value:*):void {
    _map[key] = value;  // _map is a Dictionary 
}

How can we explain this?

_map is a Dictionary object created in JSONObject's constructor without the weakKeys parameter (i.e. it's false)

Can a simple dictionary[key]=value allocate anything??

Thanks for any help

Eyal

Scout shows that internalPut method allocated 2,355 Dictionary Objects

1

There are 1 best solutions below

0
On

So it turns out that in Flash/AS3, empty Dictionary or Array objects may internally create another instance of their own class during first object assignment, that is when the first 'put' operation on a Dictionary occurs, or the first 'push' command on an Array occurs.

From what I investigated, this will only happen when these collection objects were cleared before (i.e. they had values and then emptied via their 'delete' or 'splice' calls)

Hope it helps,

Eyal