Try profiling this code, i know its a very specific set of conditions, yet it illustrates the problem
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.setTimeout;
public class Main extends Sprite
{
private var _array:Array;
private var _xml:XML;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
setTimeout(test,5000);
}
public function test():void {
var xmlString:String = '';
var nodeString:String = '';
for (var i:int = 0; i < 50; i++) {
xmlString += nodeString;
for (var j:int = 0; j < 50; j++) {
xmlString += nodeString+'';
}
xmlString += '';
}
xmlString += '';
_xml = new XML(xmlString);
_array = [];
for each(var node:XML in _xml..node) {
//_array.push(node); // memory leak; Memory:180,691,640 during runtime
_array.push(new XML(node.toXMLString())); // no memory leak; Memory:5,290,963 during runtime
}
}
}
}
Edit:
I used flashdevelop SWF Profiler, not the most reliable tool i must say, System.totalMemory and windows Task manager showed normal memory amounts for this example even though SWF Profiler went totally crazy on me. So i started to play around. After tweaking the iterators for a while, i started to notice that memory test results became weird, spikes of memory if the cycle is over ~5000 iterations in the for each segment of the code. Maybe if you try recursive processing like in XMLLoader you will be able to recreate more controlled results