I have read some frameworks source code recently and noticed that they written the clear() method of a list-like data structure like this. Delete the elements one by one.
while (_arr.length > 0 )
{
remove(_arr[0]);
}
(maybe the above look like a little confusing,but it's because the native array type in this language itself was a dynamic array) or
for (int i = 0; i < size; i++)
{ elementData[i] = null;}
size = 0;
But i remembered i have written some code like this. The list decorated native array type,and I have written clear() method like this.
_arr=new Array();
_size=0;
instantiate a new native array type directly.
and this code are written in the language that has the garbage collection. so I think all elements finally will be collected,so why there need a loop?Is a new will be fast?