garbage collection and vectors
If I dump a lot of sprites into a vector, then want to garbage collect and repopulate the vector, what is the best way to do this? My app will be reusing the same vector over and over and I'm a bit worried it may have performance issues. Below is some pseudo code that explains.
//create vector
public var sprites:Vector.<Sprite>;
function someFunction(data:Object):void {
//check if there are already sprites, if so, delete them
if(sprites) {
deleteSprites()
}
sprites = new Vector.<Sprite>();
for(var i:uint = 0; i < data.length; i++) {
sprites = new SpriteWithPNGsInside();
addChild(sprite);
}
}
function deleteSprites():void {
var spritesLength:uint sprites.length;
for(var i:uint = 0; i < spritesLength; i++) {
delete sprites;
trace(sprites); // traces: Object [SpriteWithPNGsInside]
}
}
Should I be calling something other than 'delete sprites' like 'sprites.splice(0)'?
I feel like my call to 'sprites = new Vector.<Sprite>()' should wipe them all out but I'm not sure. The sprites actually contain a few png's, and there are quite a few calls to repopulate the vector, so I think eventually there is going to be a major performance problem. Any ideas?
Thanks for the help!