Your .as file is probably either an ActionScript-only project application, in 
which case it is a class, or a script referenced by an MXML file in which case 
it is also a class.  I can’t think of a way to use AS3 w/o having one class 
definition.

The AS3 instance memory usage scheme is pretty much like C++.  Only instance 
variables add to the per-instance cost of a class.  The class definitions 
methods have a significant cost, but not per-instance.

Now for some sequence of code that creates a UI from components, there is no 
strong reason to turn that code into a class definition unless it warrants it 
based on the usual principles of computer science.  Don't forget to factor in 
maintenance costs.

You can use the profiler to compare memory footprint of your class and 
determine whether the trade-off Is worth it.


On 8/22/10 3:37 PM, "MicC" <[email protected]> wrote:






I have an .as code file that loops through creating tab panes with combo boxes 
on them, the data is retrieved from a ms cube etc, etc, etc. :-)

I was about to take this prototyping code and create a tab pane class and a 
combo box class (including the service that goes and gets the cube dimension 
data that populates the combo) when the following question occurred to me:

The .as file is one block of code that creates all these gui objects at run 
time. If this code is made into classes that "create themselves", does it by 
definition create a lot more overhead? For example, each combo box instance 
would instantiate a service var to go and get its data, whereas in the .as file 
there is one service var that is reused.

Also each tab instance and combo instance would encapsulate methods for their 
creation, and presumably would reside in memory while the instance is living. 
Flex probably keeps one copy in memory of a class(?) so there are not 10 copies 
of MyComboBox.init() for 10 comboboxes in memory, but doesn't the .as code file 
just run its code and then exit leaving a zero footprint in memory?

This Flex Dashboard app is a la SharePoint where the whole app is built at 
runtime from XML templates and the code loops through the XML constructing the 
gui. I do not know enough about the internals to know if

1. Running all the construction in the .as code file is low overhead because 
the .as code goes away after it is run?

2. Creating self-contained classes to do their own construction is high 
overhead because all that code will sit in memory for the duration of the app?

Having classes that handle themselves seems more elegant, but at what expense? 
TIA,

Mic (I know what I mean :-) )






--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui

Reply via email to