We've created a class for tracking what is in memory. It doesn't add any
cleanup functions but it gives a good indicator what's there so you can see if
your efforts are having a positive effect.
package debug {
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.utils.Dictionary;
public class ObjectMemoryWatch {
private static var objects:Dictionary;
private static var isInitialized:Boolean;
private static var timer:Timer;
private static var previousSummary:Object;
public static function initialize(timerInterval:Number =
2000):void {
// only initialize once
if (isInitialized) return;
// create a new dictionary to hold all the objects
objects = new Dictionary(true);
// create a timer for tracing at specific intervals
timer = new Timer(timerInterval);
timer.addEventListener(TimerEvent.TIMER, traceObjects)
timer.start();
};
public static function add(object:Object,
objectName:String):void {
objects[object] = objectName;
};
private static function traceObjects(event:TimerEvent):void {
// if this is the first time, trace a blank line
var firstTime:Boolean = true;
var tempArray:Array = new Array();
var currentSummary:Object = new Object();
// loop through the dictionary of objects and trace
each one
for each (var objectName:String in objects) {
if (firstTime) {
trace("");
firstTime = false;
}
tempArray.push(objectName);
//trace(objectName);
}
tempArray.sort(Array.UNIQUESORT);
for (var i:uint = 0; i < tempArray.length; i++) {
trace(i, ":", tempArray[i]);
if (currentSummary[tempArray[i]] == null) {
currentSummary[tempArray[i]] = 1;
} else {
currentSummary[tempArray[i]] += 1;
}
}
for (var itemLabel:String in currentSummary) {
trace(itemLabel, currentSummary[itemLabel]);
}
};
}
}
Then use is likeā¦
ObjectMemoryWatch.initialize();
ObjectMemoryWatch.add(moveClip, "Sound Movie Clip");
then watch the output panel it will iterate all the items in the Memory Watcher
then it will list the number of items "Sound Movie Clip" 5, 6, 7 so on.
As for Garbage Collection, it is unpredictable but we've found that the more
action on a movie the faster it runs.
Hope this helps!
Jeremy Hicks
Actionscript Developer | Clover
+ + + + + +
cloversites.com
805 527 8900
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders