Jump to content
Search Community

Memory Management issue

scottwitte test
Moderator Tag

Recommended Posts

I'm noticing a potentially troublesome memory issue with loaderMax. Essentially it seems to use up a lot more RAM than Flash's own loader, at least for a while. I noticed this in an application where where I am trying to preload many large images. Using loaderMax RAM usage increased with each load, eventually eating up 1G. It stayed there for a few seconds after loading finished then gradually decreased to where it was before loading started. No such increase happens using Flash's loader. The problem came when there wasn't a lot of free RAM, resulting in much disk thrashing that really bogged down the system.

 

A simplified version of my loaderMax code (resulting in a temporary 1G increase in RAM use):

var queue:LoaderMax = new LoaderMax;

for (var i=0; i	queue.append( new ImageLoader(xmlData.photo[i], {name:i }) );
}

queue.load();

Doesn't matter if I specify the container name, BTW.

 

By contrast, my earlier AS3 code (resulting in little to no increase in RAM use, at least until the Sprite is added to the stage):

var photos:Array = new Array();	

for (var i=0; i	loadImage(xmlData.photo[i], i)
}

function loadImage(photoURL, photoIndex):void {
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded, false, 0, true );
loader.load(new URLRequest(photoURL));

function imageLoaded(e:Event):void {
	var thisBMap:Bitmap = new Bitmap(e.target.content.bitmapData); 
	var j:int = photoIndex;
	photos[j] = new Sprite();
	photos[j].addChild(thisBMap);
   }
}

Link to comment
Share on other sites

I just tested your code and I saw virtually no difference whatsoever in memory usage between the LoaderMax one and the regular Loader-based one. Could you please post an FLA (or two) that demonstrates the issue? I wonder if there's something else going on in your code that might be causing the problem?

Link to comment
Share on other sites

 

I just tested your code and I saw virtually no difference whatsoever in memory usage between the LoaderMax one and the regular Loader-based one.


I'm guessing you tested in the Flash development environment. I just found that the difference doesn't show up there but does when the SWF is run in a browser. At least it does for me in FF3.6 and IE8 and Safari 5.

Here are the comparisons (with everything removed except for the loading code. So no fun animations):
Using LoaderMax (Demo no longer available)
Using regular AS3 (Demo no longer available)

Watch you RAM usage. (In my case I'm using Windows Task Manager, Performance Tab, Physical Memory.) In the case of the loaderMax example RAM usage increases by roughly 900MB in this test case. It plateaus, then returns to its level before running. With the regular AS3 RAM usage doesn't increase at all.

The FLA files are attached. memtest.zip
Link to comment
Share on other sites

Something fishy is going on here - I don't think your non-LoaderMax version is even loading the images. I watched my status bar on the bottom of the browser and it never once indicated a subload like it did with LoaderMax. I also noticed that you're using nested functions which are widely considered a bad practice because they get garbage collected after the parent runs (in most cases at least). I verified that was indeed happening even just in the Flash IDE - only a small subset of your Loaders were calling the imageLoaded() function properly. I believe the rest were getting garbage collected.

 

Another thing that confused me was that you seem to be expecting that loading 75+ large images wouldn't affect RAM very much. Where did you think it was storing the image data? It appears as though your images are a little larger than 1600x1900 each which, when uncompressed into memory will indeed take up about 700MB. A single image saved as a bmp was almost 9MB. So given the fact that you're using nested functions and the RAM usage isn't really increasing nearly enough to account for the images in your non-LoaderMax version, I'm pretty sure it's because the images aren't being loaded properly. LoaderMax, however, was indeed loading them properly.

 

I tried to run a quick test from my server, but since you don't have a crossdomain.xml file in place on your server and you didn't include the XML or all the images, it's a little tough to reproduce on my end (Flash throws security errors because of the crossdomain loading). If you still think there's a problem with LoaderMax, could you please post everything I need to simply publish the file(s) on my end and get a fully-functional demo of the issue? I'd make troubleshooting much easier. The FLA files were a great first step.

Link to comment
Share on other sites

Totally agree that my original code has problems -- more than you know. That is one reason I have great hope for loaderMax. The nested functions are there so I can keep the proper index variable with each image loaded. That was the solution I came up with while also allowing simultaneous downloads. There may be better ways using standard AS3 but why bother when the far superior LoaderMax is available? Regardless, images are definitely being loaded with the non-LoaderMax version. I monitor using FlashTracer and see all loads completing in both examples, at least it seems only onComplete events are being fired. I can see downloading in my network traffic and they are there when I add them to the stage.

Another thing that confused me was that you seem to be expecting that loading 75+ large images wouldn't affect RAM very much. Where did you think it was storing the image data?


They end up in the browser cache on disk. They don't seem to eat up RAM until they get added to the displayList with addChild. Even with LoaderMax RAM settles back to where it was before loading started after a few seconds. Both versions end up with the same RAM usage. LoaderMax just seems to be holding images in RAM far longer than the AS3 loader.

I appreciate your offer to look into this further. You can find all the relevant files for testing locally here: (No longer available.)

(BTW, even though I've only used the bonus features once I am more than happy to be a "Club Greensock" member. You do great work and deserve support!)
Link to comment
Share on other sites

Aha! Thanks for posting the rest of the files - it helped me identify exactly what the issue was. It had to do with the fact that ImageLoader uses a 1-pixel BItmapData and draw()s the loaded image to it in order to identify any tricky security issues. Apparently, as soon as you draw() a DisplayObject (even if it's only 1-pixel worth) Flash decides to render the whole thing as a bitmap temporarily in RAM and even forcing garbage collection doesn't release it for a few seconds. Not to worry, though - I have worked around that issue in the latest release. Please snag it at http://www.LoaderMax.com and let me know if that works better for you. Thanks for letting me know about this. I think the symptom wouldn't be noticeable for 95%+ of the users out there (you're loading a LOT of very large images, much more so than the average use case) but it's good to make this improvement in any case.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...