Monday, January 26, 2009

Dynamic objects and the Flex profiler

In certain situations it can be handy to use dynamic objects. The advantage of dynamic objects is that you can add properties at runtime (something you can't do in Java or C#). Dynamic objects are slower than 'normal' objects but there's another problem: if it's an object of type 'Object' (for example because you wrote { id: 123 } to create a dynamic object on the fly) it doesn't show up in the profiler and therefore it's hard to track the memory used by these objects. Therefore I'd recommend to declare specific dynamic classes in bigger applications. This way you cannot only track their memory usage in the profiler but you also know which type of content is in your dynamic objects (and therefore which dynamic content is eating up your memory).

package
{
public dynamic class CustomerObject
{
}
}

Before people start flaming: this post is not a recommendation to use dynamic objects because in most cases it's better not to use dynamic objects in the first place!

2 comments:

yoavm said...

This is really annoying, especially that it isn't documented anywhere.
But what about other types? I've tested the profiler and saw that XML objects aren't seen as well. Do you know of other types or why does that happen?

Palmero Tom said...

No - I can't give you a clue. Sorry!