Skip to main content
Inspiring
June 5, 2008
Question

Flash Memory Problem

  • June 5, 2008
  • 7 replies
  • 1003 views
When I load my site IE7 is taking up about 73MB of Mem Usage. But, as I continue to move from section to section the Mem Usage goes up. It can even go up as much as 600 - 700 MB!
Is there a way to keep that memory down or clear it with Actionscript?

My site is a pretty basic site that loads different sections, or external swfs, into a container or loader that's on the stage.

Any help would be greatly appreciated!

This topic has been closed for replies.

7 replies

kglad
Community Expert
Community Expert
August 26, 2008
you're either not removing all references to your loader or there's a problem with the flash gc which is affecting your project.
Participant
August 26, 2008
Thanks again!
Can you tell me one thing..
Loader is the only component for memory leak problem (if we don't remove the references) or there are some others too , like URLLoader and to some extend I've read about ExtenalInteface.
But when I try to create the URLLoader as a child of any movie clip it simply denies or through es error. Does that mean we can't remove the reference of URLLoader OR just by using removeEventListner and passing the URLLoader variable "null" will mark it for garbage collection?
awaiting for you reply.
kglad
Community Expert
Community Expert
August 25, 2008
start eliminating things done by your swf(s) to pinpoint the cause of the problem.
Participant
August 26, 2008
Thanks for the early reply.
I have eliminated URLLoader and ExternalInterface and could find the Loader as a culprit.
I have implemented the expected way as you have shown for the Loader "GC in action way".
But still the memory is not released, it starts from 65,555k and goes beyond 500,000k on every click it increases by 5mb. I don't see the GC is working. What would be the problem? Once again thanks for the early reply. and hope the same in future...
kglad
Community Expert
Community Expert
June 5, 2008
close all streams in it, remove it from the display list (if it was every in the list), remove all references to it (including listeners, weak or not) and finally assign its reference (its loader in the case of a loaded object) to null.
Inspiring
June 5, 2008
I'm using one container to house these external movie clips. That's how I always did it in AS2. Is that a bad idea in AS3? I'm also using only 1 loader. So, at the end of each movie clip this function is called:

function movieLoad(){
var request:URLRequest = new URLRequest(nextMovie + ".swf");
loader.load(request);
container.addChild(loader);
}

There must be some better way to do this?

kglad
Community Expert
Community Expert
June 5, 2008
weak references in listeners and the dictionary class don't work. or, at least, they didn't work with earlier versions of the flash player. i haven't tested recently.

in any case, either test or explicitly remove listeners, remove unused objects from the display list, close unneeded streams and null all objects when they are ready to be gc'd.
Inspiring
June 5, 2008
So, I'm guessing that my externally loaded swf is considered an object. And, that object needs to be nulled? How would one go about nulling an swf file?
June 5, 2008
It's not that hard, you just need to take into consideration more aspects of whatever you want to accomplish.
Inspiring
June 5, 2008
Perhaps "very frustrating" would be a better description of my experience with these memory leaks. It doesn't seem like the old garbage collector is doing anything for me.
June 5, 2008
Load the external swf files once. That means that you need to re-use the ones that you have already loaded.
Inspiring
June 5, 2008
Honestly, I can't tell if it's reusing the swf or not? Perhaps, my code will tell?

// This loads the first movie
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest(nextMovie + ".swf");
loader.load(request);
container.addChild(loader);

// This loads the next movie according to the which button the user pressed
function movieLoad(){
container.removeChild(loader);
var request:URLRequest = new URLRequest(nextMovie + ".swf");
loader.load(request);
container.addChild(loader);
}
June 5, 2008
quote:

Originally posted by: troyboy777
// This loads the next movie according to the which button the user pressed


Yep, you are loading the same content everytime those buttons are pressed. You need to check somehow wether you have loaded the content related to each button before actually loading an external swf.

If you have loaded something already, and you don't need it for a moment but eventually you will, then hide it instead of loading it again.
kglad
Community Expert
Community Expert
June 5, 2008
read about garbage collection (gc) in flash.
Inspiring
June 5, 2008
Thanks for the tip. I've now added weak references to my event listeners, but I'm still having the same problem. It seems that each time an external swf is loaded into my loader the site keeps growing and growing. My old sites in actionscript 2 only occupied about 70MB of Mem Usage. I must be missing something in actionscript 3?