furyan.be
January 14th, 2009, 07:11 PM
Hi, im trying to get a deeper understanding on how as works, I was wondering:
for(var i:int = 0; i < 100; i++)
{
var s:Sprite = new Sprite();
s.name = "sprite"+i;
addChild(s);
}
var s is a reference to the the new Sprite
new Sprite is stored inside memory at some place
var s is also stored inside memory but only takes a small amount of space because it only needs to point to new Sprite?
the second time the loop runs, will the old var s be overwritten in memory? or will it be asigned to a new position in memory?
would it be beneficial if i typed something like this?
for(var i:int = 0; i < 100; i++)
{
var s:Sprite = new Sprite();
s.name = "sprite"+i;
addChild(s);
s = null
}
for(var i:int = 0; i < 100; i++)
{
var s:Sprite = new Sprite();
s.name = "sprite"+i;
addChild(s);
}
var s is a reference to the the new Sprite
new Sprite is stored inside memory at some place
var s is also stored inside memory but only takes a small amount of space because it only needs to point to new Sprite?
the second time the loop runs, will the old var s be overwritten in memory? or will it be asigned to a new position in memory?
would it be beneficial if i typed something like this?
for(var i:int = 0; i < 100; i++)
{
var s:Sprite = new Sprite();
s.name = "sprite"+i;
addChild(s);
s = null
}