1 Reply Latest reply on Apr 29, 2008 7:40 AM by lk88

    HTTPService + XML Load + Memory Leak

    ljonny18 Level 1
      Hi all....

      I have noticed a memory leak in my application. This leak was not apparent when the application was completed some months back which is what left me a little confused as all I have done since was upgrade to Flex 3 and possibly updated / changed my Flash player.

      I think I have found the cause to this problem (below) but am not 100% sure that it is the "actual" problem or any reasons to back my thoughts up, so have listed what I have checked / tried along the way (maybe I have missed something)....

      My Discovery Process:
      I started profiling my application but did not find anything out of the ordinary. I did a code walk-through double checking I had cleaned up after myself, removing and even nulling all items etc but still to now success - the leak is still there.

      I have profiled the app in the profiler for reasonably long periods of time.
      All the classes etc being used within the app are consistent in size and instance amount and there is no sign of any apparent leak.

      I am using a HTTPService that is loading XML data which I am refreshing every 5 seconds. On this 5 second data refresh some class instances are incremented but are restored to the expected amount after a GC has occurred. The GC seems to take longer, the longer the app is running, therefore more and more instances are being added to the app, but when the GC eventually runs it "seems" to clear these instances to the expected amount.

      After scratching my head for a while I decided to make a copy of my application, rip everything out, and focus in my data load, where I found a problem!
      I have now just a HTTPService that loads an XML file every 5 seconds, and this is all I currently have in the app (as I ripped the rest of the code out), e.g:


      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" ....... creationComplete="initApp()" >

      url=" http://myIP:myPort/myRoot/myXML.cfm"
      result="httpResultHandler(event)" />

      <script....... >

      private var timerPulse:Timer;

      private function initApp():void
      timerPulse = new Timer(5000, 0);

      private function httpResultHandler(event:ResultEvent):void
      timerPulse.addEventListener(TimerEvent.TIMER, timerRefresh);

      public function timerRefresh(eventObj:TimerEvent):void
      timerPulse.removeEventListener(TimerEvent.TIMER, timerRefresh);


      This is pretty much the code I am currently using and it leaks.
      I ran and monitored this in both the profiler and the activity / task manager, and after running the app for 1800 seconds (30 min) in the profiler, the memory size grew from 50mg to 165mg just sending the HTTPService.

      I tried loading the service in multiple ways including in AS rather than MXML creating new instances of it each time, resetting it, nulling it etc... but nothing prevented this memory increase.
      I then tried to load the XML using different methods such as using the URLRequest and URLLoader which again caused a memory leak.

      What still confuses me is that this leak did not exist in the previous version and not a great deal has changed since then apart from upgrading to Flex 3 and possibly upgrading my Flash payer (which I believe is a possible cause)

      After looking into this issue a bit more deeply, I read a few blogs / forums and other people are experiencing the same problems - even with a lot bigger leaks in some cases all when reloading large sets of XML data into Flex - however, I as of yet found no solution to this leak - people with a similar problem believe it is not due to a memory leak more a GC error, and others pointing towards the Flash Player itself that is leaking - I don't really know.

      Findings so far during investigation of this issue:

      * App leaks for both HTTPService and ULRRequest / URLLoader methods
      * App only leaks when calling a data loader
      * The size of the leak seems to depend on the size of the XML being loaded
      * The size of the leak also seems to be affected by the applications heaviness - the greater seems to enhance the leak

      An interesting factor I have noticed is that if I copy the XML from my "myXML.cfm" that I link to in my HTTPService and copy the contents of the file into my own XML file stored within the Flex project root itself: ""myXML.xml"" the leak disappears... like it seems to link when loading the XML over a network, however as my network knowledge is not great I am not sure what to make of this - any ideas???

      Could the connection to the XML document cause leaks??? is there anything else that could cause this leak??? have I something in my code sample that could cause this leak??? or could any of the other things I have mentioed cause this leak???

      Any help / ideas would be greatly appreciated.

        • 1. Re: HTTPService + XML Load + Memory Leak
          I also observed heavy memory leak from using httpservice with XML data. I am using Flex3 builder under Linux. My Flex application polls httpservice every 10 seconds. The reply is a short XML message less than 100 bytes. This simple polling will consume 30+ MB of memory every hour. I leave it idling for several hours and it took 200 MB of memory. No sign of garbage collection at all.