A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: URLLoader/URLReqest memory leak problem.

  1. #1
    Junior Member
    Join Date
    Mar 2011

    URLLoader/URLReqest memory leak problem.

    I have the following code where I am pulling XML weather data from NOAA. This is an AIR app. Everything loads fine but, every time it is loaded it adds about 1.3mb to the System.totalMemory check I'm testing. It seems like there is a cache that needs to cleared somewhere or there is a leak. I have searched and found some that say there is a leak but, can anyone tell from my code below if I am clearing everything I should?

    I have shorted the code, there are actually 6 cities in my final file.


    Actionscript Code:
    import flash.net.URLLoader
    import flash.net.URLRequest
    import fl.containers.UILoader;

    var xmlSomeCity1:XML;
    var xmlSomeCity2:XML;

    var loaderOne:URLLoader = new URLLoader();

    loaderOne.load(new URLRequest("link to file"));
    loaderOne.addEventListener(Event.COMPLETE, processSomeCity1XML, false, 0, true);

    function processSomeCity1XML(e:Event):void
        xmlSomeCity1 = new XML(e.target.data);
        _somecity1.location_somecity1.text = xmlSomeCity1.location;
        _somecity1.time_somecity1.text = xmlSomeCity1.observation_time;
        _somecity1.weather_somecity1.text = xmlSomeCity1.weather;
        _somecity1.temperature_somecity1.text = xmlSomeCity1.temperature_string;
        _somecity1.humidity_somecity1.text = xmlSomeCity1.relative_humidity + "%";
        _somecity1.wind_somecity1.text = xmlSomeCity1.wind_dir + " at " + xmlSomeCity1.wind_mph;
        _somecity1.pressure_somecity1.text = xmlSomeCity1.pressure_in + " inches";
        _somecity1.dewpoint_somecity1.text = xmlSomeCity1.dewpoint_string;
        _somecity1.visibility_somecity1.text = xmlSomeCity1.visibility_mi + " miles";
        _somecity1.icon_somecity1.source = "link to file" + xmlSomeCity1.icon_url_name;
        _progressBar1._bar.scaleX = 0.1666;
        loaderOne.removeEventListener(Event.COMPLETE, processSomeCity1XML);
        loaderOne.load(new URLRequest("link to file"));
        loaderOne.addEventListener(Event.COMPLETE, processSomeCity2XML, false, 0, true);

    function processSomeCity2XML(e:Event):void
        xmlSomeCity2 = new XML(e.target.data);
        _somecity2.location_somecity2.text = xmlSomeCity2.location;
        _somecity2.time_somecity2.text = xmlSomeCity2.observation_time;
        _somecity2.weather_somecity2.text = xmlSomeCity2.weather;
        _somecity2.temperature_somecity2.text = xmlSomeCity2.temperature_string;
        _somecity2.humidity_somecity2.text = xmlSomeCity2.relative_humidity + "%";
        _somecity2.wind_somecity2.text = xmlSomeCity2.wind_dir + " at " + xmlSomeCity2.wind_mph;
        _somecity2.pressure_somecity2.text = xmlSomeCity2.pressure_in + " inches";
        _somecity2.dewpoint_somecity2.text = xmlSomeCity2.dewpoint_string;
        _somecity2.visibility_somecity2.text = xmlSomeCity2.visibility_mi + " miles";
        _somecity2.icon_somecity2.source = "link to file" + xmlSomeCity2.icon_url_name;
        _progressBar1._bar.scaleX = 1.0000;
        loaderOne.removeEventListener(Event.COMPLETE, processSomeCity2XML);
        _somecity2.icon_somecity2.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);

    function completeHandler(event:Event):void
        loaderOne.data = null;
        loaderOne = null;
        _somecity2.icon_somecity2.removeEventListener(Event.COMPLETE, completeHandler);

  2. #2
    Flactionscrish Baby Minion's Avatar
    Join Date
    Nov 2005
    Planet Earth
    you should switch two lines in the completeHandler function

    loaderOne.data.clear() should come before loaderOne = null

    also, do you have access to a profiler? you could use that to see if it is the loader that is not dying or some xml objects? the profiler could really help you determine which objects are piling up. (Flash Builder and FlashDevelop have them)
    he who hesitates is lost; so i guess i'll wander intently

    Are you sure this is real?
    Life is Love, Love is Blind, Blind we go through Life.
    Life isn't hard, dealing with your self is.

    The concept of life in a human brain is weakening day after day. Live every day like its your last. Take the chances, and opportunities, and never let authority push you around for fun.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center