PDA

View Full Version : setAlign() memory leak?


kbriggs
02-26-2008, 01:46 PM
OL 4.0.8

Are there any known issues with LzView.setAlign()? I've got a game application running in a window component. I noticed that the longer the game runs, the longer it takes for that window to close. I tracked it down to one line of code in the game loop:

this.TName[i].setAlign("center");

TName is an array(10) of LzText whose parents are LzView's with a 90x35 pixel PNG resource. Anyway, if I comment out that line or change the value to "left", the window will close immediately no matter how long the game runs. With it in, it takes several seconds and up to getting a warning from the flash player about a slow running script, depending on how long I let it run, where that line would have been called hundreds of times.

I tried creating a small app to demonstrate the problem but no luck so far duplicating the slow closing window.

pal
02-26-2008, 03:18 PM
I think you are right. I made a small testcase and as I call .setAlign("center") I can see firefox's memory usage go higher and higher. It seems it's the same on dhtml.

Here is my testcase:

<canvas debug="true">

<resource name="arespng" src="lz/resources/checkbox/autoPng/checkbox_disable_on.png"/>


<class name="testclass">

<view resource="arespng"/>

<text name="text" y="20"/>

</class>


<window name="test1" width="500" height="200" bgcolor="0xff0000" closeable="true">

<attribute name="texts" value="$once{[]}"/>

<method name="init">
<![CDATA[
super.init();
this._resizeControl
for (var i = 0; i < 10; i++)
{
var text = new testclass( this.wframe.wcontent, {'x':10+i*45, 'y':20} ).text;
text.setText( i );
texts.push( text );
}
]]>
</method>


<handler name="onvisible">
this.destroy();
</handler>


<button text="setVAlign" x="20" y="100">
<handler name="onclick">
<![CDATA[
var texts = parent.texts;
for (var j = 0; j < 500; j++)
{
for (var i = 0; i < texts.length; i++)
{
texts[i].setAlign("center");
}
}
]]>
</handler>
</button>


</window>

</canvas>

senshi
02-29-2008, 02:18 PM
Yes, there is a mem-leak bug, it's fixed in the latest dev-branch.
Basically one constraint is created for every "setAlign" call, but this constraint won't be destroyed. But this also means in your case, that you actually don't need to call "setAlign" for all your views, as the constraint is still active.
Changing the x-pos directly should also work for you:


var myview = ?
myview.setAttribute("x" , myview.immediateparent.width/2 - myview.width/2);

kbriggs
02-29-2008, 02:46 PM
But this also means in your case, that you actually don't need to call "setAlign" for all your views, as the constraint is still active.


True but I haven't yet optimized my game loop so it's just doing a brute force update as it doesn't know its previous state.


Changing the x-pos directly should also work for you:


Good idea, I'll do that in the mean time. Thanks.