Quantcast
Channel: Adobe Community: Message List - Memory issue when Loading an asset with URLRequest from a remote location
Viewing all articles
Browse latest Browse all 32

Re: Memory issue when Loading an asset with URLRequest from a remote location

$
0
0

Okay, I spent a bunch of time looking at this today.

 

I like Flash Pro much better than the other tools, so everything is just a FLA now. 

 

I've included copies of the examples, SWFs and Scout Files from the tests I did.

https://sendnow.acrobat.com/?i=FQjtw62IW7L*wKmTw4-3gw

 

Long story short, you're doing a bunch of extra work in the onClick() handler. 

 

function onClick(e:MouseEvent):void

{

    _loader = new Loader();

    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

    //var urlReq:URLRequest = new URLRequest("camera.swf");

    var urlReq:URLRequest = new URLRequest("http://lorenz82.altervista.org/camera.swf");

    var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);

    _loader.load(urlReq, loaderContext);

}

 

In a production implementation, you'd only want to grab each asset once from the network, then clone where necessary.  You'd also want to avoid making new URLRequest and loaderContext objects each time, if they're going to remain static -- although they're pretty small.

 

Your observation is correct that there's a difference between passing the Loader object off to the DisplayList when you're loading via a remote URL; however, I think what you're seeing is that we're optimizing in the case where we're grabbing the object off the local filesystem.  The memory usage reflected in Scout is under Uncategorized, which basically lumps all of the objects that are automatically created together (as opposed to the ones you've created through ActionScript itself). 

 

In my implementation, I move all this stuff up into init(), and then just clone the already loaded bytes into new Loaders that get passed to the DisplayList.

 

function init(e:Event = null):void

{

    removeEventListener(Event.ADDED_TO_STAGE, init);

    stage.addEventListener(MouseEvent.CLICK, onClick);

 

    loader = new Loader();

    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

 

    var url:URLRequest = new URLRequest("http://lorenz82.altervista.org/camera.swf");

    var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);

 

    loader.load(url,context);

}

 

function onClick(e:MouseEvent):void

{

    if(isLoaded) {

        var clone:Loader = new Loader();

        clone.loadBytes(loader.contentLoaderInfo.bytes);

        map["camera"+camCount] = clone;

        map["camera"+camCount].x = Math.random() * stage.width;

        map["camera"+camCount].y = Math.random() * stage.height;

        addChild(map["camera"+camCount]);

        camCount++;

    }

}

 

I'll ask a few of the people that know the Flash Player Internals to double-check, but I'm pretty sure that this is not a bug.  Either way, this probably isn't something you want to do in a real application.

 

Thanks!


Viewing all articles
Browse latest Browse all 32

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>