2 Replies Latest reply on Oct 19, 2011 1:53 PM by drkstr_1

    how to prepare list for garbage collection after drag and drop operation

    drkstr_1 Level 4

      Hello all,

       

      I have a view in a mobile application which contains a list using drag and drop. The problem that I am having is that the NativeDragManagerImpl holds onto a reference to this list in its _dragInitiator and _relatedObject properties. This is not a memory leak per-say, since the reference will be replaced next time drag and drop is used, however, this is preventing my entire view from garbage collecting, causing an unaceptable peak memory.

       

      Here is an example that demonstrates the problem (Default AIR app using Flex 4.5.1):

       

      Main.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:local="*"
                                                           xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark" width="800"
                                                           height="600">
      
      
                <fx:Script>
                          <![CDATA[
                                    protected function start_clickHandler(event:MouseEvent):void
                                    {
                                              var element:ListGroup = new ListGroup();
                                              this.panel.addElement(element);
                                    }
      
                                    protected function stop_clickHandler(event:MouseEvent):void
                                    {
                                              this.panel.removeAllElements();
                                    }
                          ]]>
                </fx:Script>
      
      
                <s:Panel id="panel" top="100" left="100" bottom="100" right="100" title="Drag Drop Test">
                          <s:controlBarContent>
                                    <s:Button label="Start" click="start_clickHandler(event)" />
                                    <s:Button label="Clear" click="stop_clickHandler(event)" />
                          </s:controlBarContent>
                </s:Panel>
      
      
      </s:WindowedApplication>
      
      

       

      ListGroup.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
                           xmlns:s="library://ns.adobe.com/flex/spark" width="100%" height="100%">
                <s:layout>
                          <s:HorizontalLayout />
                </s:layout>
                <s:List id="sourceList" width="100%" height="100%" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true">
                          <s:dataProvider>
                                    <s:ArrayCollection>
                                              <fx:String>Item 1</fx:String>
                                              <fx:String>Item 2</fx:String>
                                              <fx:String>Item 3</fx:String>
                                              <fx:String>Item 4</fx:String>
                                    </s:ArrayCollection>
                          </s:dataProvider>
                </s:List>
                <s:List id="targetList" width="100%" height="100%" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true">
                </s:List>
      </s:Group>
      
      

       

      If you drag any items to the right list, there will always be at least one instance of ListGroup stuck in memory for the duration of the execution (as seen in the profiler).

       

       

       

      Is there a way to perform a clean up on the DragManager (or actually the underlying DragManagerImpl) at a time of my choosing? Any thoughts or ideas will be greatly appreciated!

       

       

      Many thanks for your time!