10 Replies Latest reply on May 16, 2008 5:06 AM by Mirza Asim

    AdvancedDataGridItemRenderer Memory Leak

      In one of my applications I use a lot of AdvancedDataGridItemRenderers to shade, bold, color, etc. data differently depending on the the data value and column. I used the same technique of extending DataGridItemRenderer in Flex 2. The problem is using the profiler I discovered that my custom AdvancedDataGridItemRenderes never garbage collect as the data changes and eventually just add up until the program grinds to a halt, while my regular DataGridItemRenderers garbage collect just fine.

      What am I doing wrong? Is there a workaround?
        • 1. Re: AdvancedDataGridItemRenderer Memory Leak
          Sreenivas R Adobe Employee
          This seems to be strange as there seems to be nothing speical in your custom itemRenderer.

          Few points to check.

          1. The number of instances may be more but are you sure they are all live?
          2. If you use the default ItemRenderer without any customization do they still accumulate?
          3. Is it possible to write a simple sample which shows the problem?
          • 2. Re: AdvancedDataGridItemRenderer Memory Leak
            Mirza Asim
            This is infact a problem in AdvancedDataGrid. Even I am also facing the same problem and I posted this problem on Adobe Bugs Forum. Here is the reference key "FLEXDMV-1685".
            They accepted it as a performance issue and said that they will try to fix in the immediate release
            • 3. Re: AdvancedDataGridItemRenderer Memory Leak
              Level 1
              After a lot more investigation I think the problem might be FLEXDMV-1685. While the item renderers never garbage collect, when I turn off all my custom renderers my AdvancedDataGrid's still leak memory like crazy, probably because I'm using large amounts of data and often create new arrays of columns for the same AdvancedDataGrid. So what is the work around here?

              I'm going to check tomorrow to see if completely destroying the AdvancedDataGrid and creating a new one instead of just assigning new columns triggers garbage collection and stops the memory leak. Any other suggestions would be helpful.

              Thanks
              • 4. Re: AdvancedDataGridItemRenderer Memory Leak
                Sreenivas R Adobe Employee
                By extending ADG and adding the following code should help.

                override public function set columns(value:Array):void
                {
                super.columns = value;
                itemRendererToFactoryMap = new Dictionary(false);
                }

                Let me know if it doesn't.
                • 5. Re: AdvancedDataGridItemRenderer Memory Leak
                  Mirza Asim Level 1
                  Thanks for the workaround. Its working fine as far as the AdvancedDataGridHeaderRenderer and AdvancedDataGridItemRenderer are concerned but number of instances of AdvancedDataGridColumn are still in the increasing state.
                  • 6. Re: AdvancedDataGridItemRenderer Memory Leak
                    Level 1
                    Yes, extending the ADG worked, and garbage collection is finally working for AdvancedDataGridItemRenderers in my program. Thanks for your help. I have some other memory leaks to track down, but this has at least turned off the fire hose.

                    I can more easily work around the changing columns issue, but it would be helpful if there was a way to get garbage collection working for that as well.

                    Thanks,
                    Dave
                    • 7. Re: AdvancedDataGridItemRenderer Memory Leak
                      Sreenivas R Adobe Employee
                      When I run GC in the profiler even the columns are getting freed. I am unable to see any memory leak with respect to columns. Is it possible that something else in your app is causing the problem?

                      If you have a sample which leaks it would help me trace the problem.
                      • 8. Re: AdvancedDataGridItemRenderer Memory Leak
                        Mirza Asim Level 1
                        Following is the sample code. In this code 'ImporvedAdvancedDataGrid' is your mentioned extended grid.

                        Attach Code
                        <?xml version="1.0" encoding="utf-8"?>
                        <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" preinitialize="startApp()">

                        <mx:Script>
                        <![CDATA[
                        import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;

                        [Bindable]
                        private var dp:Array= [
                        { column1 : "11", column2 : "12", column3 : "13" },
                        { column1 : "21", column2 : "22", column3 : "23" }
                        ]
                        private var adg:ImprovedAdvancedDataGrid;
                        private var counter:int=0;

                        private function startApp():void
                        {
                        adg= new ImprovedAdvancedDataGrid();
                        adg.x= 300;
                        adg.y= 100;
                        adg.setActualSize(adg.getExplicitOrMeasuredWidth(), adg.getExplicitOrMeasuredHeight());
                        adg.columns= this.createCol();
                        adg.dataProvider= dp;
                        this.addChild(adg);
                        }

                        private function createCol():Array
                        {
                        var cols:Array= new Array();
                        var c:AdvancedDataGridColumn;

                        for ( var i:int=0; i<3; i++ )
                        {
                        c= new AdvancedDataGridColumn()
                        c.dataField= "column" + (i+1);
                        c.headerText= "column" + (counter++);
                        cols.push(c);
                        }
                        return cols;
                        }

                        public function onClick():void
                        {
                        adg.columns= createCol();
                        adg.validateNow();
                        }
                        ]]>
                        </mx:Script>

                        <mx:Button id="btn" label="Change Columns" click="onClick()"/>

                        </mx:Application>
                        • 9. Re: AdvancedDataGridItemRenderer Memory Leak
                          Sreenivas R Adobe Employee
                          With the above code I am seeing only 6 columns in the instance count column after running GC/while taking a memory snapshot.

                          So I am assuming the fix I have given is freeing up the columns also.

                          Without my fix I can see the column count growing with the fix I see it growing but on running GC it is getting freed.
                          • 10. Re: AdvancedDataGridItemRenderer Memory Leak
                            Mirza Asim Level 1
                            Well in my application, addition and deletion of columns is a very frequent operation since we present users with a list of data providers to choose for viewing in data grid. Your solution requiring me to invoke garbage collector on every change of data provider is not acceptable since this is going to incur a significant performance overhead. It is interesting to note that unreferenced column instances are not freed up automatically when the gc is invoked by the framework. Only when the gc is invoked explicitly are the instances disposed off. I would appreciate if the issue could be addressed as soon as possible.