6 Replies Latest reply on May 18, 2009 4:20 AM by Patrisce

    Flex memory increases dramatically

    Patrisce

      Using a DataGrid and a simple Graph to display 50000 rows of xml data (e4x), causes Flex memory to increase dramatically.

      If you click and get the data several times (see attached sources ), you will eventually get the System memory to go over 1GB, which is way too much to handle for a standard browser/windows client (Internet Explorer 7, Flex 3.2, Flash Player 10).

       

      Note that in this example, I have tried to reproduce a problem that I have in a real world application. I always handle the data the same way:

      1. I get the data from HTTPservice as e4x

      2. I Load the data in a XMLListCollection source

      3. I assign the XMLListCollection source as a DataProvider to several graphs and datagrids.

       

      Please take a look at the source and let me know if I am doing anything wrong.

      Any help would be appreciated, as our customer is getting very impatient.

       

       

      -----------------------source--------------------------------------------------

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
           xmlns:local="*" width="100%" height="100%">
               <mx:Label id="totalMemory" styleName="linkBarMenu" text="{(System.totalMemory / 1024) + 'KB'}" render="totalMemory.text = (System.totalMemory / 1024) + 'KB'"/>
              <mx:Button label="get data" click="getData()"/>
               <mx:AdvancedDataGrid id="myDgd1" dataProvider="{rsltFilterXML}">
                  <mx:columns>
                      <mx:AdvancedDataGridColumn dataField="N"/>
                      <mx:AdvancedDataGridColumn dataField="NAME"/>
                      <mx:AdvancedDataGridColumn dataField="AGE"/>
                      <mx:AdvancedDataGridColumn dataField="HEIGHT"/>
                  </mx:columns>            
               </mx:AdvancedDataGrid>
              
               <mx:AreaChart dataProvider="{rsltFilterXML}" width="100%" showDataTips="true">
                   <mx:series>
                  <mx:PlotSeries id="customeSerie" yField="AGE" xField="N"/>
                  </mx:series>
          </mx:AreaChart>

       


             
          <mx:HTTPService id="GetData" resultFormat="e4x" result="sasResults(event)" fault="handleFault(event)"  
             method="POST" showBusyCursor="true"/>

       

      <mx:Script>
        <![CDATA[
                import mx.collections.XMLListCollection;
                import mx.controls.Alert;
                import mx.rpc.events.FaultEvent;
              import mx.rpc.events.ResultEvent;         
              [Bindable] private var  rsltFilterXML:XMLListCollection = new XMLListCollection();

       

              private function getData():void
              {
                  rsltFilterXML.source = null;
                  GetData.url="classroom.xml";
                   GetData.send();
              } 

       

                 public function handleFault(event:FaultEvent):void
              {
                 Alert.show(event.fault.faultString, event.fault.message);
              }        

       

              private function sasResults(event:ResultEvent):void
                {
                  rsltFilterXML.source = event.result.row; 
                }
             
          ]]>

       

        </mx:Script>
         
         
      </mx:Application>

        • 1. Re: Flex memory increases dramatically
          Patrisce Level 1

          Attaching data (classroom.xml)

          • 2. Re: Flex memory increases dramatically
            Srirangan Level 2

            Hi,

             

            You can consider using pagination by assigning a filter function on the dataProvider of the DataGrid.

             

            Or you might want to check out a lightweight DataGrid replacement: http://www.elfgrid.com/

             

            - Sri

            • 3. Re: Flex memory increases dramatically
              Michael Borbor Level 4

              Profile your app, to display the 50000 records Flex has to loop 

              through each one, and using an XMLListCollection adds more overhead to 

              this operation if the binding isn't important don't use 

              XMLListCollection.

               

              Sincerely,

               

              Michael

               

              El 18/05/2009, a las 4:35, Patrisce <forums@adobe.com> escribió:

               

              >

              Attaching data (classroom.xml)

              >

              • 4. Re: Flex memory increases dramatically
                Patrisce Level 1

                Do you mean that even though I only display 10 rows, then flex will loop and assign memory to 50 000? I know it is a lot, but still the memory should not increase when assigning new data to the XMLListCollection. GC should eventually occur.

                • 5. Re: Flex memory increases dramatically
                  Patrisce Level 1

                  Now I have tried to remove the datagrid and the chart, and the Bindable, and use an ArrayCollection. The memory is still increasing. Is there a way to clean up the data before getting some new? I am guessing that Flex accumulates the data instead of cleaning up. Note that you only see this problem when you are dealing with a lot of data (size > 50000)

                   

                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:elfgrid="http://www.elfgrid.com/2009"
                       xmlns:local="*" width="100%" height="100%">
                           <mx:Label id="totalMemory" styleName="linkBarMenu" text="{(System.totalMemory / 1024) + 'KB'}" render="totalMemory.text = (System.totalMemory / 1024) + 'KB'"/>
                          <mx:Button label="get data" click="getData()"/>
                         
                      <mx:HTTPService id="GetData" resultFormat="object" result="sasResults(event)" fault="handleFault(event)"  
                         method="POST" showBusyCursor="true"/>

                   

                  <mx:Script>
                    <![CDATA[
                        import mx.collections.ArrayCollection;
                            import mx.collections.XMLListCollection;
                            import mx.controls.Alert;
                            import mx.rpc.events.FaultEvent;
                          import mx.rpc.events.ResultEvent;         
                          private var orgData:ArrayCollection;

                   

                          private function getData():void
                          {
                              GetData.url="classroom.xml";
                               GetData.send();
                          } 

                   

                             public function handleFault(event:FaultEvent):void
                          {
                             Alert.show(event.fault.faultString, event.fault.message);
                          }        

                   

                          private function sasResults(event:ResultEvent):void
                            {
                              orgData = new ArrayCollection(event.result.row); 
                            }
                         
                      ]]>

                   

                    </mx:Script>
                     
                     
                  </mx:Application>

                  • 6. Re: Flex memory increases dramatically
                    Michael Borbor Level 4

                    I checked your code breifly, it's a nightmare review code in a cell 

                    phone, that's where Profiling comes in handy, somehere there must be a 

                    memory leak, or the ADG isn't doing something right.

                     

                    In order to the GC to run all reference to an object must be remove, 

                    in your case that wouldn't happen because you use the XML always, I 

                    didn't see a filter in your app to show only 10 records, probably I 

                    missed it.

                     

                    Sincerely,

                     

                    Michael

                     

                    El 18/05/2009, a las 5:55, Patrisce <forums@adobe.com> escribió:

                     

                    >

                    Do you mean that even though I only display 10 rows, then flex will 

                    loop and assign memory to 50 000? I know it is a lot, but still the 

                    memory should not increase when assigning new data to the 

                    XMLListCollection. GC should eventually occur.

                    >