9 Replies Latest reply on Jul 13, 2009 2:21 PM by Flex harUI

    Memory usage - leak or not?

    ethr

      Im working with a charting application that plots thousands of points. The data is downloaded via AMFPHP and displayed in a PlotChart.

       

      Situation: repeatedly running the chart shows an ongoing increase in browser memory usage (as noted by Task Manager). Eventually it crashes the browser and the PC.

       

      Viewing the application in the profiler (Flex Builder 3.0.2) shows no growth in memory. Examining "Lingering Objects" shows nothing out of the ordinary. It grows to a plateau at about 20M and then stabilizes. I see the GC running between memory snapshots.

       

      Flash 9.xx. Reproducible using Flash 10.xx

       

      Appears in FF 3.0 and Chrome 2.x

       

      Recommendations on how best to approach this?

        • 1. Re: Memory usage - leak or not?
          Flex harUI Adobe Employee

          Start chopping.  Don't plot the data in a Chart, just download the data and see if memory grows.  Then download two data sets and switch them in and out of the Chart and see if memory grows.  That can help you identify where the memory growth is coming from.

           

          It is probably the data side.  Sometime the browser have their own IO buffers and don't release them when they should.  Maybe fetching subsets of a smaller size will help.

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Memory usage - leak or not?
            ethr Level 1

            Great! I commented out the line where I assign my ArrayCollection of data points to the 'series' property. Now it plateaus after 5 iterations of downloading the data. I can see the GC kick in.

             

            Given that Im not getting any 'lingering objects' in the profiler I assume (naively) that this means Im not holding any references to the data between loadings.

             

            Recommendations?

            • 3. Re: Memory usage - leak or not?
              Flex harUI Adobe Employee

              What plateus?  Profiler Memory or Task Manager memory?  Does your app still run out of memory eventually?

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              • 4. Re: Memory usage - leak or not?
                ethr Level 1

                Plateau: task manager - at ~200K. The profiler has never reported any issues. It peak at ~20K even when the task manager shows the browser memory increasing out of range.

                 

                If I don't connect the ArrayCollection to the graph then the application doesn't run out of memory.

                • 5. Re: Memory usage - leak or not?
                  Flex harUI Adobe Employee

                  OK, now take two ArrayCollections of different points and swap them into the chart.  If memory keeps growing then there is a leak in the chart code or a custom renderer if you have any.

                   

                  If memory doesn't keep growing, then it indicates you are outrunning GC.  That so many new objects have to be created as new data arrives and is charted that the GC can't keep up.  Lookinf for ways to recycle existing objects might help.

                   

                  Alex Harui

                  Flex SDK Developer

                  Adobe Systems Inc.

                  Blog: http://blogs.adobe.com/aharui

                  • 6. Re: Memory usage - leak or not?
                    ethr Level 1

                    Im working on this test but I can't believe that I've found a bug in this element. Surely there is something wrong with my code. I must have a reference count to the data set somewhere. Is there a way to force the chart code to reset?

                     

                    EDIT:

                    So I fixed this problem by creating / removing the plotchart in AS instead of relying on the MXML version. If the appropriate Panel child exists I remove it and recreate it when the new data comes in. The GC is clearing up the debris appropriately now.

                    • 7. Re: Memory usage - leak or not?
                      Flex harUI Adobe Employee

                      You can try creating a new chart.  However, the profiler, if you are using it correctly should be showing that is leaking.  See the profiler tutorial on my blog.

                       

                      Alex Harui

                      Flex SDK Developer

                      Adobe Systems Inc.

                      Blog: http://blogs.adobe.com/aharui

                      • 8. Re: Memory usage - leak or not?
                        ethr Level 1

                        I did the following:

                         

                        1) start app

                        - mem snapshot (a)

                        2) create graph

                        - mem snapshot (b)

                        3) create graph

                        - mem snapshot (c)

                        4) create graph

                        - mem snapshot (d)

                        5) delete plotchart object via parent.RemoveObjectAt() to get the reference and then set the reference = null.

                         

                        The creation of each plotchart is preceded by the same "remove / delete" call.

                         

                        Doing the 'lingering objects' test between a and b shows 1 instance of plot data. Goes to reason as the graph is there.

                        Same test between b and c shows 1 instance. Implies that the previous was GC'd properly.

                        Same test between c and d shows no graph data.

                         

                        Here's the odd one: test between a and d shows the most recent instance of the plot data (as shown in the 'object references' view) as 'lingering'.

                         

                        Overall memory in the 'memory usage' window shows the expected rise and fall between getting the data and the GC call. It returns to the same value after every pass of the GC (initiated by the 'snapshot' command).

                         

                        I believe the graph data is being GC'd but Im a bit puzzled by the a/d comparison. This suggests that even though the plot chart has been (mostly) GC'd there is some residue. It may be this data that is accumulating in my original case ( loading my plot data into a plotchart defined in MXML ).

                         

                        Not sure. Ideas on how to clean it up?

                        • 9. Re: Memory usage - leak or not?
                          Flex harUI Adobe Employee

                          You cannot use loitering objects if you are 'replacing' things.  If a plot chart is still supposed to be around, then you have to manually compare snapshots.  That's explained on my blog.

                           

                          Alex Harui

                          Flex SDK Developer

                          Adobe Systems Inc.

                          Blog: http://blogs.adobe.com/aharui