Hi there,

I'm experiencing some weird behaviour when using Bindings. In short, when I remove some object from the DisplayList which has declared any Binding, the garbage doesn't destroy this object from memory causing unwanted binding triggers and an innecesary increase of memory usage.

Here's an example which isolates the problem. It consists in 2 mxml's (Main.mxml and MyScreen.mxml) and 1 .as. (ModelLocator.as)

Main.mxml consists of one button and an empty mx:Canvas. When the button is clicked three actions are taken:
       1. A property in the ModelLocator is increased by one.
       2. Remove all canvas children.
       3. Create a new instance of MyScreen component
       4. Add the MyScreen instance to the canvas displayList.

On the other hand, MyScreen.mxml just declares a binding from the testVar property declared in the ModelLocator to a setter. In this setter a simple trace is performed.

The problem is seen when clicking several times the button.
       1. The first time you click it only one trace is printed.
       2. The second time you click it, the trace is performed twice. One for the new created instance an one for the removed one.
       3. The third time you click it, the trace is performed 3 times, one for each instance of MyScreen that has been previously been instanciated.
       4. and so on...

I'm not sure if this is a bug or not, but I think it's not the expected behaviour and lots of applications can suffer a serious decrease of performance due to this issue. I've been digging on the auto generated code trying to isolate where the bindings where declared. I'm not sure, but maybe the problem has to be something with weakreferences.

So the question is, how could I workarround this? Is there anyway I can force binding to stop working? remove it? or whatever? maybe declare it as a weakreference and not as a strong reference?

Help is much apreciated!

Here's the isolated code:

[CODE --- main.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml "
    layout="vertical" >
   
    <mx:Script>
        <![CDATA[
            private var i:int = 0;
           
            private function loadChild():void
            {
                ModelLocator.getInstance().testVar = i++;

                container.removeAllChildren();
                var s:MyScreen = new MyScreen();
                container.addChild (s);
            }
        ]]>
    </mx:Script>
   
    <mx:Button label="load" click="loadChild()"/>
    <mx:Canvas id="container" width="100%" height="100%"/>
</mx:Application>
[/CODE]

[CODE -- MyScreen.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml ">
    <mx:Script>
        <![CDATA[
            protected function set dest (d:String):void
            {
                trace ("modified");
            }
        ]]>
    </mx:Script>
   
    <mx:Binding source="ModelLocator.getInstance().testVar" destination="dest"/>
   
    <mx:Text text="hola mundo"/>
</mx:Canvas>
[/CODE]


[CODE -- ModelLocator.as]
package  {
    [Bindable]
    public class ModelLocator {
        private static var instance:ModelLocator;
       
        public function ModelLocator() {
            instance = this;
        }
       
        public static function getInstance():ModelLocator {
            if (instance == null) {
                instance = new ModelLocator();
            }
           
            return instance;
        }
       
        public var testVar:int;
    }
}
[/CODE]


Thanks so much
X.

P.D: this is the third time I send this question, hope this time someone can help :-)
__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to