PDA

View Full Version : Removing Images from Memory in a loop



melacroso
August 14th, 2009, 12:29 PM
Hiya everybody.

Friday eve nightmare hehe. I've made a script which loads in, at intervals, images in a sequence (image1.jpg, image2.jpg,..... ). However I've being doing my nut as to how to remove the preceeding image from memory as looking a the Windows Task Manager, each image gets added again and again, accumulating memory usage.

I've tried removeChild, and null; stuff, but to no avail.

I want it to go through the 10 images, and with each step to the next image, remove the last one from memory. Make sense?

Or if you have any ideas of a better way of doing this?

Script is below.

Thanks for reading, have a good weekend

:samus_v2:

---------------------------------------------------------------------------

stop();
var j:int = 0;
var mLoader:Loader = new Loader();
function PicLoad(i:int)
{

var mRequest:URLRequest = new URLRequest("folder/image"+i+".jpg");
mLoader.load(mRequest);
addChild(mLoader);

}
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
function onTimer(evt:TimerEvent):void {

if(j>9){j=1;


}
else{

j++
};
PicLoad(j);
};

.ral:cr
August 14th, 2009, 01:02 PM
in the way you've done it, it should already be garbage colected because you have a single loader for multiple images. when you load one, the previous one is removed because can't coexist in the loader.
the problem is that GC is not doing the job immediately, so you can try to load more images to see when some memory is freed.

melacroso
August 17th, 2009, 06:39 AM
Good point, I think I'll leave it as it is as the way it is on the site and the image sizes are not going to make a massive diffence (unless someones on the site for like 2hours).

Thanks for your help chum,

All the best

Melacroso

:hobbes::samus_v2: