4 Replies Latest reply on Dec 11, 2007 10:08 AM by m_hartnett

    Memory increases more and more ! Help

    Jean Demonceau
      Hi, i've got a problem. My application is composed with a big tabnavigator. Tabs are added and removed dynamically based on certain conditions. To remove tabs i use the removeAllChildren methode and to add tabs i use addChild methode.

      The problem is that the memory used by my browser increases continually when tabs are added and do not decrease when tabs are removed ... I think that tabs still are in memory and should be killed by the garbage collector or something else...

      My browser takes approximately 60MB in memory when i start the application and takes 120MB after 3 minutes (up to 200MB and more)...

      Someone has any idea how i can solve this problem ?
        • 1. Re: Memory increases more and more ! Help
          m_hartnett Level 3
          This is a great presentation on the problems you are having.

          You may want to change the way those buttons are built.
          In one of my apps I create a max number of buttons and then bind each button to properties of an object I call the navBtnObj.
          That object has properites like navUrl, navVisible .... so on.

          My bar is built by changing the visible attribute of the object. Since the button is bound to this value it will show or hide by just changing the visible property.

          This also gives a more predictable behaviour of memory management.

          • 2. Re: Memory increases more and more ! Help
            paulfeuer Level 1
            you might try double-checking your use of listeners with regard to the components you're tossing. if you register a listener *from* one of those components, when you toss it, the event dispatcher that has your child's listener may retain a reference to it, possibly preventing it from being garbage collected.

            if you're using dynamically created functions, you may want to avoid those if you can. by dynamic function i mean like something.addListener( "change", function( evt:Event ):void { dosomething=0; } );

            • 3. Memory increases more and more ! Help
              Jean Demonceau Level 1
              Thank you for your answers.

              mhartnett I can't instantiate all my tabs in the begining of the application and set visible to false those I don't need because each tab does specifics tasks and must be added in certains conditions. So I use the AddChild method of the tabnavigator in differents state and the RemoveAllChildren method when the state is leaved. But apparently, they still are in memory.

              I've read these comments

              and i'm not alone in that case...

              They said that eventlisteners must are weakly referenced : addEventListener("click",fct,false,0,true)

              I did this everywhere in my application and the memory increases less than before but still increase too much ...

              I'm wondering if listeners in mxml code are weakly referenced or not? if i have to set my listeners weekly referenced in the mxml code => write btn.addEventLister(MouseEvent.Click,showLogin,false,0,true) instead of <mx:Button id="btn" label="login" click="showLogin()" /> ???

              Isn't it a little be crazy ?

              I also saw that transitions effects cause memories allocations and don't free memory..?
              I also saw that children has to remove all listener from there parents...
              Some people say that flex's framework should be all re-writed ...

              I'm wondering if flex is really powerfull with a "big" management application... I thing flex is only good for little effects, only for the show but not for real database treatments. Am I wrong ?

              • 4. Re: Memory increases more and more ! Help
                m_hartnett Level 3
                I have to agree with you.
                We build enterprise apps with flex 2 but eliminate the use of most of the 'flashy' options of the language.

                Everything is carefully constructed to remove and add the event listeners where needed and have not had too many memory issues.

                Overall I think Flex is the best on the market and will improve as the new versions come out.