You might be interested to know that JavaScript doesn't have a local scope for a for
loop. It's scoping is based on functions. Hence, you should not redeclare var myImg
more than once in a function.
Going back to your code, I would suggest that you only declare one new Image()
(i.e. outside the loop), which should be more efficient
var i, myImg = new Image();
for(i = 0; i < 100; i++) {
myImg.src = getNewSource();
}
The delete
property is meant for removing an item from an object. For example:
var myObj = { a: 2, b: 3 };
delete myObj.a;
// myObj will now be { b: 3 }
However, this does not necessary release the memory, but the reference to the item in the object. The memory is claimed back by the JavaScript garbage collector (and you cannot trigger this in your code)
Hope this helps