Pano2VR Draining my memory

Q&A about the latest versions
Post Reply
garethLee
Posts: 2
Joined: Wed Oct 29, 2008 6:32 pm

Hi all,

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
		}
	}
}
User avatar
thomas
Chief Gnome
Posts: 2613
Joined: Fri Sep 01, 2006 3:56 pm
Location: Vienna, Austria
Contact:

Hmmm... does the panorama include a skin?
MfG, Thomas
garethLee
Posts: 2
Joined: Wed Oct 29, 2008 6:32 pm

Hi Thomas,

No, the Panorama doesn't include a skin but I do think that this may be a flash bug rather then a pano2VR bug. In flash 10 there will be a loader.unloadAndStop() method to help rectify the problem of external content lingering in the memory, this will only work if all refrences to objects are nulled and their listeners are removed, also the use of weak references in event listeners will help the Garbage Collector mark objects for removal which in turn would result in the removal.

So if in the external movie/panorama you have the following scenario in a cleanup() method.....

Code: Select all

myObject = loader.content
otherObject = myObject

otherObject = null
myObject.removeEventListener(.......)
removeChild(myObject)
myObject = null
loader.unloadAndStop()
This should enable the garbage collector to completely destroy any loaded content.

Adobe claim that this currently is ony a problem when you have timers or enter frame events running in external content, but i've found that this isn't the case and even empty movies cause memory problems. :(
User avatar
thomas
Chief Gnome
Posts: 2613
Joined: Fri Sep 01, 2006 3:56 pm
Location: Vienna, Austria
Contact:

I tested it again, and somehow the garbage collector can not free my skin object?!? In older version I created the skin object in any case but with the next 2.2beta2 the skin object is nulled if there is no skin embedded. This should allow the complete removal of the panorama.
MfG, Thomas
Post Reply