Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was skeptical/intrigued after looking at the code that there would be any memory leaks so I tested out your code for myself.</p> <p>The code you posted isn't actually run able. I just added the bare minimum to have it run like app tag and import statements (and a counter label to see when a http service cycle completes):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="application1_creationCompleteHandler(event)"&gt; &lt;mx:Script&gt; &lt;![CDATA[ import mx.rpc.http.HTTPService; import mx.collections.XMLListCollection; import mx.rpc.events.ResultEvent; import mx.events.FlexEvent; private var xmlC:XMLListCollection = new XMLListCollection(); private var httpS:HTTPService = new HTTPService(); private var timer:Timer = new Timer(1000); private var xmlData:XML; private var xmlDataList:XMLList; protected function application1_creationCompleteHandler(event:FlexEvent):void { httpS.url = "data.xml"; httpS.addEventListener(ResultEvent.RESULT, resultHTTP); httpS.resultFormat="e4x"; httpS.send(); timer.start(); timer.addEventListener(TimerEvent.TIMER, updateXMLC); } private function updateXMLC(event:TimerEvent):void { xmlC.source = xmlDataList; httpS.send(); } private function resultHTTP(event:ResultEvent):void { counter.text = Number(parseInt(counter.text,10)+1).toString(); xmlData = event.result as XML; xmlDataList = xmlData.dg.rows.row; } ]]&gt; &lt;/mx:Script&gt; &lt;mx:Label id="counter" text="0" horizontalCenter="0" verticalCenter="0" fontSize="72"/&gt; &lt;/mx:Application&gt; </code></pre> <p>The good news is there aren't any memory leaks in your code. There also aren't any loitering objects in profiler either.</p> <p>The bad news is whatever else you're doing in your application (code that is not posted up here, omitted for whatever reason) - that is where you have a leak / loitering objects.</p> <p>You can see for yourself in profiler of the attached code, that the memory doesn't increase after the first few cycles of the http service. I.e. it doesn't continue grasp more memory over time. (By the way, the XML file I'm pulling in is about 8000 rows, over 1MB).</p> <p>If you'd like to post more code, happy to look further - but think this solves this mystery for now. ;)</p> <p>Here's some fixes for what your doing:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="application1_creationCompleteHandler(event)"&gt; &lt;mx:Script&gt; &lt;![CDATA[ import mx.rpc.http.HTTPService; import mx.collections.XMLListCollection; import mx.rpc.events.ResultEvent; import mx.events.FlexEvent; [Bindable] private var xmlC:XMLListCollection = new XMLListCollection(); private var httpS:HTTPService = new HTTPService(); private var timer:Timer = new Timer(1000); private var xmlData:XML; private var xmlDataList:XMLList; private var serviceRunning : Boolean = false; private var currentData : String = ''; protected function application1_creationCompleteHandler(event:FlexEvent):void { httpS.url = "data.xml"; httpS.addEventListener(ResultEvent.RESULT, resultHTTP); httpS.resultFormat="e4x"; httpS.send(); timer.start(); timer.addEventListener(TimerEvent.TIMER, updateXMLC); } private function updateXMLC(event:TimerEvent):void { xmlC.source = xmlDataList; if( !serviceRunning ){ // don't call for more data until httpS.send(); // you've gotten back last call } } private function resultHTTP(event:ResultEvent):void { // make sure we have differences before rebinding var newData : String = event.result as String; serviceRunning = false; counter.text = Number(parseInt(counter.text,10)+1).toString(); if( newData != currentData ){ xmlData = event.result as XML; currentData = newData; xmlDataList = xmlData.dg.rows.row; } } ]]&gt; &lt;/mx:Script&gt; &lt;mx:Label id="counter" text="0" horizontalCenter="0" verticalCenter="0" fontSize="72"/&gt; &lt;/mx:Application&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload