4 Replies Latest reply: Apr 12, 2012 1:42 PM by mitz11 RSS

    Module mysteriously leaks when contents are resized.

    mitz11 Community Member

      I have an mx module that I'm loading up, and normally it loads and unloads just fine.  However, after shifting around some of its contents, I noticed it was leaking. This is a basic userID / password module, there's nothing too fancy going on.  It looks like this:           .... some script....                                                                                                                                                                                                           The custom class "SpecialModule" is a simple override of mx:Module that has a timer (with a *weak* reference) that just writes to the trace log every 20 seconds so I can tell if the module is leaking or not.   Exactly as it is, this code does not leak.  HOWEVER, if I change the height="100%" part of the top level VGroup container to height="70%", the module leaks without fail.  The same occurs if I try to add a label outside the VGroup, or over the top of it.  It seems to occur completely at random based on the positioning of the components inside of it, but when it leaks, it leaks 100%, and when it doesn't, it doesn't.  I removed all styling code, including embedded fonts, etc, and it doesn't make any difference.  any thoughts?

        • 1. Re: Module mysteriously leaks when contents are resized.
          mitz11 Community Member

          None of my MXML pasted... bear with me a minute.

          • 2. Re: Module mysteriously leaks when contents are resized.
            mitz11 Community Member

            in the first post, where ".... some script ...." is, there should be this:

             

            <SpecialModule xmlns="common.*" xmlns:fx="http://ns.adobe.com/mxml/2009" width="100%" height="100%" xmlns:s="library://ns.adobe.com/flex/spark"

              creationComplete="creationCompleteHandler()" xmlns:controls="controls.*" layout="absolute">

             

                 <fx:Script> .... some script .... </fx:Script>

             

                 <s:VGroup width="100%" height="100%" gap="10">

                      <s:Image source="./assets/images/logo.png" width="100%" height="65%" horizontalAlign="center" verticalAlign="top"/>

                      <s:HGroup width="100%" height="10%" gap="20" verticalAlign="middle">

                           <s:Label id="operIdLabel" left="0" width="50%" height="100%" text="{_IDText}" textAlign="right" color="white" verticalAlign="middle"/>

                           <s:BorderContainer id="operIdBorder" minHeight="15" minWidth="45" width="50%" height="100%" borderColor="#FFFF00" borderWeight="2">

                                <s:TextInput id="operIdText" click="focusID()" width="100%" height="100%" right="0" focusEnabled="false" editable="false" />

                           </s:BorderContainer>

                      </s:HGroup>

                      <s:HGroup width="100%" height="10%" gap="20" verticalAlign="middle">

                      <s:Label id="passwdLabel" left="0" width="50%" height="100%" text="{_passText}" textAlign="right" color="white" verticalAlign="middle"/>

                      <s:BorderContainer id="passwdBorder"  minHeight="15" minWidth="45" height="100%" width="50%" borderColor="#FFFF00" borderWeight="2">

                           <s:TextInput id="passwdText" click="focusPassword()" focusEnabled="false" editable="false" height="100%" right="0" width="100%" displayAsPassword="true"/>        

                      </s:BorderContainer>

                      </s:HGroup>

                      <s:Label id="messageLabel" left="0" height="5%" width="100%" text="" fontSize="18" textAlign="left" color="#FF0000"/>

                 </s:VGroup>

            </SpecialModule>

            • 3. Re: Module mysteriously leaks when contents are resized.
              mitz11 Community Member

              I'm not sure, but it seems to have something to do with the contents of the VGroup going outside of the VGroup's bounds.  Thus, when I lowered the height percentage, the 10 pixel gap between objects caused the heights of all the child elements to add up to more than 100% of the height. 
              Why that would cause a memeory leak, though, is beyond me.

              • 4. Re: Module mysteriously leaks when contents are resized.
                mitz11 Community Member

                I'm now convinced this is a flex bug.  I'm using SDK 4.5.1.  I wrote the following app which distills the bug down to the simplest form that I could manage. The code for the application below is followed by the code for a module, called "module.mxml".  As is, this code will leak - just click the button a lot to reload the module repeatedly, and watch the memory usage relentlessly rise.  If you change the VGroup height to "100%" instead of "50%", it will not leak - the memeory usage will raise for a while, and then plane off.  Could someone please confirm, or tell me where I'm going wrong?
                Sorry about the poor formatting.

                 

                 

                <?xml version="1.0" encoding="utf-8"?>

                <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                 xmlns:s="library://ns.adobe.com/flex/spark"

                                                 xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="800" minHeight="600" creationComplete="creationCompleteHandler()" >

                          <fx:Script>

                                    <![CDATA[

                                              import mx.core.IVisualElement;

                                              import mx.events.ModuleEvent;

                                              import mx.modules.IModuleInfo;

                 

                                              public var info:IModuleInfo;

                                              import mx.modules.ModuleManager;

                                              private function onLoad():void

                                              {

                                                        for (var i:int = 0; i < this.numElements; i++)

                                                        {

                                                                  var removeElement:IVisualElement;

                                                                  removeElement = this.getElementAt(i);

                                                                  if ((removeElement != buttonThing) && (removeElement != memoryLabel))

                                                                  {

                                                                            this.removeElementAt(i);

                                                                            i--;

                                                                  }

                                                        }

                                                        info = ModuleManager.getModule("./module.swf");

                                                        info.addEventListener(ModuleEvent.READY, onModuleReady);

                                                        info.load(null, null, null, moduleFactory);

                                              }

                 

                                              private function onModuleReady(e:ModuleEvent):void

                                              {

                                                        var element:IVisualElement = info.factory.create() as IVisualElement;

                                                        element.width=350;

                                                        element.height=325;

                 

                                                        this.addElement(element);

                                              }

                 

                 

                                              private var memoryTimer:Timer = new Timer(1000);

                 

                                              private function creationCompleteHandler():void

                                              {

                                                        memoryTimer.addEventListener(TimerEvent.TIMER, onTimer);

                                                        memoryTimer.reset();

                                                        memoryTimer.start();

                                              }

                                              private function onTimer(e:TimerEvent):void

                                              {

                                                        System.gc();

                                                        try

                                                        {

                                                                  new LocalConnection().connect("blah");

                                                                  new LocalConnection().connect("blah");

                                                        }

                                                        catch (e:*)

                                                        {

                                                        }

                                                        memoryLabel.text = String(flash.system.System.totalMemory / 1024).toString() + "KB";

                                              }

                                    ]]>

                          </fx:Script>

                 

                          <s:Button id="buttonThing" click="onLoad()" x="400" width="100" height="100" label="load"/>

                          <s:Label id="memoryLabel" width="100" height="50" x="400" y="100"/>

                </s:Application>

                 

                 

                <?xml version="1.0" encoding="utf-8"?>

                <s:Module xmlns:fx="http://ns.adobe.com/mxml/2009"

                                      xmlns:s="library://ns.adobe.com/flex/spark"

                                      xmlns:mx="library://ns.adobe.com/flex/mx">

                     <s:VGroup width="100%" height="50%">

                                           <s:HGroup width="100%" height="10%">

                                                           <s:TextInput width="100%" height="100%"/>

                                           </s:HGroup>

                             </s:VGroup>

                </s:Module>