Skip to main content
Participating Frequently
February 8, 2008
Question

System.totalMemory / unload / IE (2 questions)

  • February 8, 2008
  • 10 replies
  • 892 views
hello guys, i ve been playing with AS3 from a while and i noticed 2 things

after a huge search i could find my answers, so tell me what do you think please.

1/ i am trying to load images and monitor the System.totalMemory i noticed that even if i unload and remove the listner and give it 500 ms so the GC do its job but the unloaded images data are always there... please see the attached file u ll notice that the totalMemory (in the FLASH DEV ENVIROMENT) increase and increase and this is a small image what about if i am loading huge images...

2/ talking about huge images well replace the img.jpg with something bigger and open your performance monitor and run the html page in IE notice that the memory consumed by the IE page increase and increase and never stop (its LIKE in the FLASH DEV ENVIROMENT)... but in FF or swf its ok .

so the question here is the unload remove the data or what? or am i doing something wrong that make the GC never remove the data. And how would i manage the IE issue??

FILE: Link


Thanks
This topic has been closed for replies.

10 replies

kglad
Community Expert
Community Expert
August 29, 2008
you must stop all streams in a loaded swf before readying for gc.

other than that nugget, i'm not sure what to offer. your code shows nothing relevant to your text.
kglad
Community Expert
Community Expert
February 10, 2008
you're welcome
August 28, 2008
Hi,
I also facing the same memory problem.
As you said in this case it works fine. But my case i am not loading images instead i load swf file which has sound embeded to the timeline as stream.

According to this code, same memory management performs well for me also. but the sound in the unloaded swf is still audible and when i load the next swf, these all sounds mix up and i don't hear anything properly.

To avoid the sound problem i added a line SoundMixer.stopAll() to getaway the problem, but after i added this line memory management got lost and my system gets hanged.


import fl.controls.List;
import fl.data.DataProvider;
var tl:MovieClip = this;

var loader:Loader = new Loader();
var myList:List=new List();
var dp:DataProvider=new DataProvider();
tl.addChild(loader);
addChild(myList);



function loadNext(e:Event) {
//loader.unload();
loader.contentLoaderInfo.removeEventListener(Event.INIT,loadNext);

tl.removeChild(loader);
loader = null;

loader = new Loader();
tl.addChild(loader);

var o=new Object();
o.label=String(Math.floor(System.totalMemory/1024));

dp.addItemAt(o,0);
myList.dataProvider=dp;
setTimeout(loadNow,100,null);
}
//start loading
function loadNow(e) {
loader.contentLoaderInfo.addEventListener(Event.INIT,loadNext,false,0,true);
loader.load(new URLRequest('img.jpg'));
}
loadNow(null);
Participating Frequently
February 10, 2008
ok thank you.
Participating Frequently
February 9, 2008
how about like this

import fl.controls.List;
import fl.data.DataProvider;

var loader:Loader=new Loader();

addChild(loader);

trace(System.totalMemory);



function loadNext(e:Event){
loader.contentLoaderInfo.removeEventListener(Event.INIT,loadNext);
loader.unload();
removeChild(loader);
loader=null;

//setTimeout(loadNow,500,null);
setInterval(display,1000);
}
//start loading
function loadNow(e){
loader.contentLoaderInfo.addEventListener(Event.INIT,loadNext,false,0,true);
loader.load(new URLRequest('img.jpg'));
}
loadNow(null);
function display(){
trace(System.totalMemory);
}

Display

6008832
10850304
10850304
10850304
10850304
10850304
10850304
10850304
10850304
10850304
10850304
.
.
.
kglad
Community Expert
Community Expert
February 10, 2008
you're not repeatedly loading anything though. which is good because you'd be creating multiple intervals which would, sooner or later, crash your flash player. and nothing is being gc'd.

if you want to see the gc in action try something like:

kglad
Community Expert
Community Expert
February 9, 2008
you're not nulling the loader and you're not removing it from the display list so it can't be gc'd. and you're reusing it repeatedly so it's going to occupy increasing amount of system memory.
Participating Frequently
February 9, 2008
hello,
i am unloading / loading an image continuasly to check if the memory get cleared or not, heres my code

import fl.controls.List;
import fl.data.DataProvider;

var loader:Loader=new Loader();
var myList:List=new List();
var dp:DataProvider=new DataProvider();
addChild(loader);
addChild(myList);



function loadNext(e:Event){
loader.unload();
loader.contentLoaderInfo.removeEventListener(Event.INIT,loadNext);
var o=new Object();
o.label=String(System.totalMemory);
o.data=System.totalMemory;
dp.addItemAt(o,0);
myList.dataProvider=dp;
setTimeout(loadNow,500,null);
}
//start loading
function loadNow(e){
loader.contentLoaderInfo.addEventListener(Event.INIT,loadNext,false,0,true);
loader.load(new URLRequest('img.jpg'));
}
loadNow(null);

when i run the swf in the IE i got the memory increased each time i load the image which mean the unload is not working properly...

Any Ideas Why?
kglad
Community Expert
Community Expert
February 9, 2008
i have no idea what you're really checking. but it is clear you have some problem because in no situation should a memory use continue to increase.
Participating Frequently
February 9, 2008
Hello and thanks for your reply
but why if i run the SWF in the FireFox browser and monitor the memory, it will appear that it is gorbage collected but in Internet Explorer the memory just increase ....


Amen
kglad
Community Expert
Community Expert
February 9, 2008
the gc does not run based on time. it runs based on memory consumption. and you must remove all object references to enable an object to be gc'd.
Participating Frequently
February 9, 2008
anyone?