0 Replies Latest reply on Apr 16, 2012 8:46 AM by mitz11

    s:TextInput with small height value causes modules to leak

    mitz11

      I posted about this a few days ago, but I hadn't pinned the problem down at the time, because this is a strange one. 

      If anyone has a solution to fix this, PLEASE tell me.

      Basically, in SDK 4.5.1 and SDK 4.6, when I load a module with a s:TextInput component that has a very small height attribute, it causes that module to stay in memory. 

       

      I wrote a small application to demonstrate the bug as simply as I could manage - here it is:

       

      <?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">

       

                <fx:Script>

                          <![CDATA[

                                    import mx.core.IVisualElement;

                                    import mx.events.ModuleEvent;

                                    import mx.modules.IModuleInfo;

                     import mx.modules.ModuleManager; 

                                    public var info:IModuleInfo;

                                    private var moduleNumber:Number = 0;

       

                      private function onLoad():void

                      {

                          for (var i:int = 0; i < this.numElements; i++)  //remove all components but the button and label

                          {

                             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;

                                              moduleNumber++;

                                              element["id"] = moduleNumber.toString();

                                              this.addElement(element);

                                              cleanup();

                                    }

                      //this funciton will force garbage collection.

                                    private function cleanup():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>

       

      And here is the module that it loads:

       

      <?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" creationComplete="onCreation()">

       

                <fx:Script>

                          <![CDATA[

                                    private var timer:Timer = new Timer(1000, 0);

                                    private function onCreation():void

                                    {

                                              timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);

                                              timer.start();

                                    }

       

                                    private function onTimer(e:TimerEvent):void

                                    {

                                              trace ("ping! " + this.id);

                                    }

                          ]]>

                </fx:Script>

       

                          <s:TextInput height="5" />

      </s:Module>

       

      Run in debug mode so you can watch the console, or if you have the memory profiler, I'm sure that would work too.

      If you leave the textinput with a very low height, like above, the module will not be cleaned up in memory.  If you change it to anything greater than 21, it will clean up properly.  Width doesn't seem to matter.

      Someone please confirm this bug for me.

      Also, please tell me if there is some workaround to this.  The application I'm working on has resizable components, and these memory leaks are killing it.  I could switch to mx:TextInput, which doesn't seem to have this problem, but then I can't use my embedded fonts and all my formatting gets messed up, and it will take a long time to fix.