简体   繁体   中英

Itemrender of DataGroup won't release memory - flex(Adobe air)

i have a datagroup compoenent in Adobe Air application and i have used custom itemrenderer in it, i attached source code of itemRenderer as well as i attached profiling of it,

Question: When i come back from other module to the module which have this datagroup at that time it again create Objects for itemrender and previous object of itemrender wont released.

if you have idea, please suggest me

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:s="library://ns.adobe.com/flex/spark"
                xmlns:mx="library://ns.adobe.com/flex/mx"
                autoDrawBackground="false"
                buttonMode="true"
                click="clickHandler(event)"
                mouseChildren="false"
                rollOut="rollOutHandler(event)"
                rollOver="rollOverHandler(event)"
                removedFromStage="itemrenderer1_removedFromStageHandler(event)"
                creationComplete="itemrenderer1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import coX.XXXXXXXXXXXXXXX.event.ThumbEvent;

            import mx.events.FlexEvent;

            protected function image_completeHandler(event:Event):void
            {
                ConsoleUtils.logIt(" ThumbImage.mxml :image_completeHandler - ");
                image.removeEventListener(Event.COMPLETE, image_completeHandler);
                fadeIn.target=image;
                fadeIn.play();
            }

            protected function clickHandler(event:MouseEvent):void
            {
                owner.dispatchEvent(new ThumbEvent("itemclick", data, itemIndex));
            }

            protected function rollOverHandler(event:MouseEvent):void
            {
                owner.dispatchEvent(new ThumbEvent("itemrollover", data, itemIndex));
            }

            protected function rollOutHandler(event:MouseEvent):void
            {
                owner.dispatchEvent(new ThumbEvent("itemrollout", data, itemIndex));
            }

            protected function itemrenderer1_removedFromStageHandler(event:Event):void
            {
                this.removeEventListener(Event.REMOVED_FROM_STAGE, itemrenderer1_removedFromStageHandler);
                this.removeEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
                this.removeEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
                this.removeEventListener(MouseEvent.CLICK, clickHandler);

                this.removeAllElements();
            }

            protected function itemrenderer1_creationCompleteHandler(event:FlexEvent):void
            {
                this.removeEventListener(FlexEvent.CREATION_COMPLETE, itemrenderer1_creationCompleteHandler);
                image.source="test.png";
                //image.addEventListener(Event.COMPLETE, image_completeHandler);
            }

        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:Fade id="fadeIn"
                alphaFrom="0"
                alphaTo="1"/>
    </fx:Declarations>

    <s:BitmapImage id="image"

                   horizontalAlign="center"
                   smooth="true"
                   smoothingQuality="high"
                   verticalAlign="middle"/>
    </s:ItemRenderer>

Snapshot of Profiling profiling_snapshot_which_shows_memory_leak

as you can see, in profile, i have 21 orphan objects which won't recyle and profiling shows me that at saved at line no 12 while line no 12 is creation_complete event and i have removed it.

Thanks in Advance

i have used DataGroup as parent component and i have define above itemRenderer in itemRenderer property of the DataGroup , and in dispose function i have define DataGroup.itemRenderer is null in DataGroup . so it will eligible for GC. and i see that now no instance of itemRenderer is in memory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM