flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Taylor <ja...@dedoose.com>
Subject RE: massive memory leak in Flex
Date Thu, 02 Mar 2017 23:32:19 GMT
negative, taking that out (that was an accident copied over from my real test), has no effect,
and neither does setting the data provider to null

<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="OnCreationComplete(event)">
    <s:List width="100%" height="100%" id="list" itemRenderer="TestItemRenderer"/>
    <fx:Script><![CDATA[
        import mx.collections.ArrayCollection;
        import mx.events.FlexEvent;

        private var _bindTimer:Timer;

        private function OnCreationComplete(event:FlexEvent):void
        {
            _bindTimer = new Timer(500);
            _bindTimer.addEventListener(TimerEvent.TIMER, OnBindTimerTick, false, 0, true);
            _bindTimer.start();
        }

        private function OnBindTimerTick(event:TimerEvent):void
        {
            BindData();
        }

        private function BindData():void
        {
            var items:Array = [];
            for (var i:uint = 0; i < 100; i++)
            {
                items.push(GenerateRandomString(100));
            }
            list.dataProvider = null;
            list.dataProvider = new ArrayCollection(items);
        }

        private function GenerateRandomString(strlen:Number):String
        {
            var chars:String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var num_chars:Number = chars.length - 1;
            var randomChar:String = "";

            for (var i:Number = 0; i < strlen; i++)
            {
                randomChar += chars.charAt(Math.floor(Math.random() * num_chars));
            }
            return randomChar;
        }
        ]]></fx:Script>
</s:Application>


-----Original Message-----
From: Alex Harui [mailto:aharui@adobe.com] 
Sent: Thursday, March 02, 2017 3:00 PM
To: dev@flex.apache.org
Subject: Re: massive memory leak in Flex



On 3/2/17, 2:56 PM, "Justin Mclean" <justin@classsoftware.com> wrote:

>Hi,
>
>Also I’d suggest making the timer multi shot rather than having the 
>recursive callLater(BindData) call.

IMO, that's the root of the problem.  The timer makes calls to BindData which also calls itself
on each frame via CallLater.  Each Timer tick adds another BindData loop.  The call count
for BindData should be going up constantly, resulting in flooding memory and GC.

But that's just by glancing at the code and screenshot, so I could be wrong.

-Alex

Mime
View raw message