I wrote the following code to check memory when loading a big image (~20Mb)
Every time I do mouse click, the application eats up memory, so something doesn’t get deleted or cleaned with GC but I can’t figure out what exactly.
Can anyone please tell me how to fix it? Thanks!
imageLoader.as
package {
import flash.display.Loader;
import flash.net.URLRequest;
public class imageLoader {
var fname:String;
var loader:Loader;
public function imageLoader(fname:String) {
this.fname = fname;
}
function init() {
loader = new Loader();
var request:URLRequest = new URLRequest(fname);
loader.load(request);
}
}
}
test.as
package {
import flash.display.MovieClip;
import flash.display.Graphics;
import flash.events.MouseEvent;
import imageLoader;
public class test extends MovieClip {
var mapImg:imageLoader;
public function test() {
var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0xff0000, 1);
mc.graphics.drawCircle(0,0,100);
mc.graphics.endFill();
addChild(mc);
buttonMode = true;
addEventListener(MouseEvent.CLICK, mouseClick);
}
private function mouseClick(e:MouseEvent) {
if (mapImg != null) {
Bitmap(mapImg.loader.content).bitmapData.dispose();
mapImg.loader.unload();
mapImg.loader = null;
mapImg = null;
}
mapImg = new imageLoader("image.png");
mapImg.init();
}
}
}