PDA

View Full Version : Disposing of a view


k-billy
09-30-2003, 11:04 AM
Hi,

is there a correct way to dispose of a view in Laszlo (We have been using the view.deleteNode() method)? Will calling this method remove the view and any other references to it, or will we have to manage references to it as well (I am assuming this is the case)?

For example, assume I have two views:

1. parentView
2. childView.

The childView node is a subview of the parentView node. At some point a user chooses to delete the childView. If the code calls childView.deleteNode(), will the parentView still have a reference to the childView?

I ask this because I want to make sure that these view are removed from memory properly, to avoid the memory usage from growing to large.

antun
09-30-2003, 03:15 PM
Calling deleteNode() still causes a memory leak, so it's not recommended at all.

If you've instantiated lots of views, then just hide them when you don't need them using setVisible(false). If they're invisible, they won't be hogging resources.

Why do you have lots of views anyway? Is this something that could be better done using data replication?

-Antun

k-billy
09-30-2003, 03:21 PM
We're building a full application for a financial client. There are going to be lots of views being used, and the user could potentially be working on the canvas for 8 hours a day.

We need to make sure that the canvas isn't crashing or slowing down excessively.

We can try to re-use existing views if necessary, but that will probably require a lot more coding.

So setting a view's visible attribute to false reduces the amount of memory the flash program is using? Is this a substantial reduction?

antun
09-30-2003, 03:47 PM
I'm going to try to give you a relevant example here:

Let's say you have a bar chart based on XML data. You should certainly try to make use of data replication to generate the chart, rather than try to loop through the data and create/delete views to match it; for example:


<canvas>

<dataset name="fin_data">
<bars>
<bar val="2" />
<bar val="4" />
<bar val="8" />
<bar val="3" />
<bar val="9" />
<bar val="3" />
<bar val="1" />
</bars>
</dataset>

<class name="bar" valign="bottom" bgcolor="blue" width="20">
<method name="applyData" args="d">
this.setHeight( (d/10) * 100 );
</method>
</class>


<view x="25" y="25" height="100" bgcolor="0xe5e5e5"
datapath="fin_data:/bars">
<simplelayout axis="x" spacing="3" />
<bar datapath="bar/@val" />
</view>

</canvas>


The data replication that's native to LZX takes care of any creation/removal of views. You could then use pooling APIs so that you don't have to delete any nodes; the re-use of views will be automatically dealt with.


So setting a view's visible attribute to false reduces the amount of memory the flash program is using? Is this a substantial reduction?


Yes, that's how the client works - things that are invisible are not taking up resources.

-Antun

k-billy
10-01-2003, 06:17 AM
I am familiar with the data replication and data pooling features of Laszlo.

To work with the example you provided, our project would require that the user could open x number of bar charts at one time. So they user could have 5 of them up, close two of them, and then open three more.

When the user creates a new chart, we would do this via ActionScript (assuming your view is a class called BarChart):

var chart = new BarChart(null, datapath:fin_data:/bars);

And when they close it, we were calling this.deleteNode() inside the BarChart class.

I think what we will do is start trying to re-use views when possible, and simply update their datapath expressions. So to take your example, we would maintain an array of BarChart instances. Whenever a user requests one, we will check the cache for a previously used BarChart.