I am working on an application which contains many components. I have been puzzled by a problem for a long time: Is the memory usage of components built with mxml tag bigger than that of components built in actionScript? I did a simple experiment below to find the truth.
Preparation: use the codes below to add new mxml component:
- <mx:Button/> <mx:TextInput/>
- <mx:Button/> <mx:TextInput/>
- <mx:Button/> <mx:TextInput/>
Comment : use copy and paste command to get enough components for this experiment.
use the codes below to add new script component:
- var amount:Number = 1;
- for(var i:Number = 0 ; i < amount; i++)
- {
- addChild(new Button());//addChild(new TextInput())
- }
Comment : use variable “amount” to control the amount of script component.
Environment:
Hardware: Intel P4 3.0G | 1.93G RAM
Operation System: Windows XP sp2
Player: Flash Player 9.0.115
Flex SDK: Flex 2.0.1 Hotfix 3
Result:
Without any Button :14596k(0)
|
|
With 1 MXML Button(1) |
With 1 Script Button(2) |
Differ Between(1-2) |
|
Memory size |
14984k |
14852k |
14984-14852=132 |
|
Differ with normal( i – 0) |
14984-14596=388 |
14852-14596=256 |
132/1 = 132 |
|
|
With 30 MXML Button(1) |
With 30 Script Button(2) |
Differ Between(1-2) |
|
Memory size |
15528k |
15352k |
15528-15352=176 |
|
Differ with normal( i – 0) |
15528-14596=932 |
15352-14596=756 |
176/30=5.8667 |
|
|
With 120 MXML Button(1) |
With 120 Script Button(2) |
Differ Between(1-2) |
|
Memory size |
17140k |
16924k |
17140-16924=216 |
|
Differ with normal( i – 0) |
17140-14596=2544 |
16924-14596=2328 |
216/120 = 1.8 |
|
|
With 240 MXML Button(1) |
With 240 Script Button(2) |
Differ Between(1-2) |
|
Memory size |
18932k |
18584k |
18932-18584=348 |
|
Differ with normal( i – 0) |
18932-14596=4336 |
18584-14596=3988 |
348/240=1.45 |
Without any TextInput:14596k(0)
|
|
With 1 MXML TextInput(1) |
With 1 Script TextInput(2) |
Differ Between(1-2) |
|
Memory size |
14988k |
14896k |
14988-14896=92 |
|
Differ with normal( i – 0) |
14988-14596=392 |
14896-14596=300 |
92/1=92 |
|
|
With 4 MXML TextInput(1) |
With 4 Script TextInput(2) |
Differ Between(1-2) |
|
Memory size |
15024k |
14968k |
15024-14968=56 |
|
Differ with normal( i – 0) |
15024-14596=428 |
14968-14596=372 |
56/4=14 |
|
|
With 30 MXML TextInput(1) |
With 30 Script TextInput(2) |
Differ Between(1-2) |
|
Memory size |
15588k |
15300k |
15588-15300=288 |
|
Differ with normal( i – 0) |
15588-14596=992 |
15300-14596=704 |
288/30=9.6 |
|
|
With 120 MXML TextInput(1) |
With 120 Script TextInput(2) |
Differ Between(1-2) |
|
Memory size |
16740k |
16520k |
16740-16520=220 |
|
Differ with normal( i – 0) |
16740-14596=2144 |
16520-14596=1924 |
220/120=1.8333 |
|
|
With 1000 MXML TextInput(1) |
With 1000 Script TextInput(2) |
Differ Between(1-2) |
|
Memory size |
30588k |
29620k |
30588-29620=968 |
|
Differ with normal( i – 0) |
30588-14596=15992 |
29620-14596=15024 |
968/1000=0.968 |
Conclusion:
With the data displayed above , as the number of components increasing, the differences between the MXML component and script component is smaller and smaller. However, the amount of components we used is among a small number commonly. so , if we want to save some memory, it’s better to use script component than mxml component.

July 9th, 2008
Ntt.cc 








Posted in
Tags: 
RSS Feed
Email Feed
Very informative! I’m curious (and don’t have the time unfortunately) to know what the difference is between MXML web service components vs AS web service declarations.
Sorry, i am being busy these days.
I will make a test with web service if i got some time.
Thank you.
[...] MXML Components VS ActionScript Components–Is the Memory Usage of Components Built with MXML t… [...]
Good information.
Sure, but is it worth it ?
Answer would be the same as:
- Is it worth writing a assembly code over C code ?
- Is it worth using a raw HTTP call over a web-service call ?
- Is it worth using plain text over XML for data transfer ?
- Is it worth rendering a web page using JavaScript than HTML itself [even if it was faster] ?
In each of these examples, latter is chosen over the former because it addresses certain principles like simplicity, ease of development/maintenance etc the former failed to address.
What margin of performance would buy you out of a fundamentally true design principle, either front-end or back-end ?
I would ask for atleast 50%, either memory or time.