I have a flash movie that needs to load in panoramas, but everytime I load in a new pano the old one is still in memory, even when using the cleanup() method. I've created a sample class to demonstrate this effect. For the example you need...
1) a button named "Button_1" that is exported for AS in the first frame
2) an external VR named "panoLarge.swf" held in a folder named "media"
When this runs it will add a pano to the stage along with a button, when the button is clicked the pano is removed and replaced by the new pano (in this example i'm just using the same pano, but the effect is the same if you use different pano's). You will see from the memory output that everytime you click the button, the memory increases until it all stalls.
I have stacked up the memory and left my machine in the hope that the Garbage Collector will eventually clear it out but after 2 hours, the memory was still full.
Any advice?
Is my code right?
Does the cleanup() method work?
Flash Specs - Flash CS3, exported in Flash Player 9
Pano Specs - Exported for Flash Player 9
Code: Select all
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.geom.*;
import flash.system.System;
import flash.utils.Timer;
public class loaderBase extends MovieClip {
var loader:Loader;
var loadedContent:MovieClip;
var b1:SimpleButton;
var a:Number = 0;
var b:Number = 0;
var c:Number=0;
var memTimer:Timer = new Timer(1000, 0);
function loaderBase() {
b1 = new Button_1;
b1.addEventListener(MouseEvent.CLICK, removeMovie);
loadNewMovie("panoLarge.swf");
memTimer.addEventListener("timer", showMemory);
memTimer.start();
}
function loadNewMovie(str:String) {
if (loadedContent != null) {
loadedContent.pano.cleanup();
removeChild(loadedContent);
loadedContent = null;
}
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded);
loader.load(new URLRequest("media/"+str));
}
function movieLoaded(e:Event) {
trace("------- MOVIE LOADED ------");
loadedContent = new MovieClip();
loadedContent = MovieClip(e.target.content);
loader.unload();
addChild(loadedContent);
addChild(b1);// so it is above panorama
}
function removeMovie(e:MouseEvent) {
loadNewMovie("panoLarge.swf");
}
public function showMemory(event:TimerEvent):void {
a = System.totalMemory;
c = a-b;
trace("Extra MEM "+(c/1000)+" total MEM "+(a/1000));
b = a
}
}
}