11 Replies Latest reply on Mar 24, 2009 7:47 AM by ice9_us

    memory leak issue

    augur_guan Level 1
      When I run my flex application in Firefox, I notice the used memory by firefox keep increasing, but I don't see the regarding memory change used by SWF file? What caused the firefox memory change if it is not caused by swf file?
      Where should I find the issue?
      I try to run some methode many times to increase used memory, the application crashed finally.
        • 1. Re: memory leak issue
          augur_guan Level 1
          we have some datagrids contains many records, the memory will increase 7MB if I clear datagrid and refill it.
          I don't know it is helpful information for your answer...(anxious)
          • 2. Re: memory leak issue
            ice9_us Level 1
            The high memory usage is typical...
            in your action script, i am willing to bet it is how you handle your variables...

            i would suggest you run debugger and check the values inside them...
            I had to call...
            in my code to help out with that issue...
            If you post your code i can help ya did it out.
            • 3. Re: memory leak issue
              augur_guan Level 1
              I have profiled the application, the memory used by SWF file is only about 20MB when I do anything in the application, but the memory used by firefox is keeping increasing, if I use group function in Datagrid, increase quicker...
              • 4. Re: memory leak issue
                augur_guan Level 1
                sorry, there is no way to show the code, it's a real and huge flex project. But i think it's a good idea to create a similar pilot project to test. thanks. When I finish, i will show it here.
                • 5. Re: memory leak issue
                  augur_guan Level 1
                  I just doubt flex holds the memory from fireforx memory every time and never release, but I don't know how it can happen, since swf file itselt does not use too much memory.
                  • 6. Re: memory leak issue
                    ice9_us Level 1
                    Fully understand what your saying..
                    i have seen it.... took me a while... but i found my problems...

                    typical stuff was --

                    var.addItem(someitem) <-- that var was growing and it was stacking data ontop... never trashing the memory that was already in the variable...

                    what i had to do was....
                    var.removeAll() or var.removeItemAt(x);

                    i also found some gotch-YAs when moving data around....

                    var:xmllist = some data
                    move to
                    var:xmllistcollection -> var:xmllist

                    would often cause issues... when doing other coppies... of the same var... i strongly suggest one copy everywhere you use the data..
                    when i cut this down.. my memory usage was cut almost in half..

                    if adding little children...
                    remove your children when no longer required and watchout for listeners...
                    They are real memory pigs for ya..
                    it is good pratice to have useWeakReference enabled...
                    remove them when not required....

                    those are typical problems which cause you the issue your seeing..

                    • 7. Re: memory leak issue
                      augur_guan Level 1
                      Sounds reasonable.
                      some code like this:
                      dataGrid.columns = new Array();
                      it's for free columns memory, and it seems should be clear using your code?
                      I did not find any method like removeAll on Array...
                      • 8. Re: memory leak issue
                        augur_guan Level 1
                        trying dataGrid.columns.splice(0);
                        • 9. Re: memory leak issue
                          -Hob Level 1
                          I doubt this will solve all your problems, but I recently identified a memory leak in the 3.2 SDK. I've written a blog post outlining what I found, with a patch file to plug the leak:

                          • 10. Re: memory leak issue
                            augur_guan Level 1
                            Yes, I have try to do the testing on that, but nothing was improved.
                            I will upgrade SDK and try again, Thank you.
                            • 11. Re: memory leak issue
                              ice9_us Level 1
                              2 things i have done..
                              closed my httpservice function
                              and changed the way my eventlistener works...

                              To give everyone some idea of what i am doing...
                              I had a timer event which restarted the process...
                              what i have done was changed the rept count from 0 to 1, the readd the timer... That has fixed my memory leak.

                              public var updateTimer:Timer;
                              public function updateInfo(event:TimerEvent):void {



                              public function process_proc_list(event:ResultEvent):void {

                              var a:int=0;

                              for ( ; this.constraintRows.pop(); );
                              for ( a=myServProcListMEM.length-1; myServProcListMEM.length > 1; a-- ) {
                              if ( myServProcListMEM.getItemIndex(a) ) {
                              for ( a=myServProcListCPU.length-1; myServProcListCPU.length > 0; a-- ) {
                              if ( myServProcListCPU.getItemIndex(a) ) {


                              proc_list_xml = event.result.process_list;

                              for ( a=0; proc_list_xml[a]; a++ ) {
                              if ( proc_list_xml[a].@server_name ) {
                              if ( proc_list_xml[a].@server_name == server ) {
                              myServProcListCPU.addItem({ProcName:proc_list_xml[a].@process_name,PCPU:proc_list_xml[a]. @pcnt_cpu_time});
                              myServProcListMEM.addItem({ProcName:proc_list_xml[a].@process_name,PMEM:proc_list_xml[a]. @pcnt_system_memory});
                              proc_list_xml = null;

                              if ( !hasEventListener(TimerEvent.TIMER) || !hasEventListener(TimerEvent.TIMER_COMPLETE) ) {
                              var mYtimer:Timer = new Timer(1000, 1 );
                              mYtimer.addEventListener("timer", updateInfo, false, 0, true);


                              <mx:HTTPService id="get_proc_list" url=" http://{Application.application.domain}/cgi-bin/get_process_data.cgi" method="POST" result="process_proc_list(event)"
                              fault="_root.faultHandler(event)" resultFormat="e4x" />