For some reason my app is using more and more memory as it runs, and I can't figure out how to dump old data I dont need anymore.
I use a Loader to load a .png I then use a BitmapData to store the image, so that I can go over and check each pixel and store the result.
Then I loop this x times.
When I start on the second run I don't need the old information anymore, but it looks like my app is still storing the data (the images loaded)..
Here's some of my code:
public function loadImage():void{
myLoader = new Loader();
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
if (currentFrame.toString(10).length == 1){
currentFrameURL = txtFolder.text + "\\" + txtImageName.text + txtImageNum.text.substr(0, txtImageNum.text.length - 1) + currentFrame + txtImageType.text;
}
if (currentFrame.toString(10).length == 2){
currentFrameURL = txtFolder.text + "\\" + txtImageName.text + txtImageNum.text.substr(0, txtImageNum.text.length - 2) + currentFrame + txtImageType.text;
}
if (currentFrame.toString(10).length == 3){
currentFrameURL = txtFolder.text + "\\" + txtImageName.text + txtImageNum.text.substr(0, txtImageNum.text.length - 3) + currentFrame + txtImageType.text;
}
trace(currentFrameURL + " sent to loader...");
myLoader.load(new URLRequest(currentFrameURL));
}
public function imageLoaded(event:Event):void{
myLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, imageLoaded);
myBitmapData = new BitmapData(parseInt(txtWidth.text),parseInt(txtHeight.text),false);
myBitmapData.draw(event.currentTarget.content);
//Generate preview of current image being processed..
//myPreviewImage.source = myBitmapData;
labelProgress.text = "Current process: " + (currentFrame + 1) + "/" + (parseInt(txtFrames.text));
for(var y:int=0; y < parseInt(txtHeight.text) ; y++){
for(var x:int=0; x < parseInt(txtWidth.text) ; x++){
currentPixelColor = myBitmapData.getPixel(x,y);
myTabelClass.recordPixel(currentPixelColor);
}
}//ett bilde ferdig scannet og lagret
currentFrame++;
if(currentFrame < parseInt(txtFrames.text)){
myTabelClass.newImg(currentFrame);
trace("sending newImg command: " + currentFrame);
loadImage();
}else{
//All frames done..
//myTabelClass.traceResult();
Alert.show("All images scanned!\n\nClick 'OK' to add new data to XML.", "Images scanned", Alert.OK, this, insertDataToXML);
btnSave.enabled = true;
btnTest1.enabled = true;
}
}