P
Peter Duniho
Ben said:It doesn't need to zero each pointer, just make the whole mess unreachable.
It does that by clearing its reference to the entire array of pointers --
O(1), not O(N).
Well, Clear() doesn't affect the Capacity of the list. So at the very
least, it has to replace that array with a new one. And the new one has
to be cleared. It may have been pre-cleared by the memory manager (I
don't know how the default values work...the built-in value types all
have a 0-equivalent default value, so I suppose the memory manager could
take advantage of that), but assuming the capacity remains the same,
somewhere at some point in time some code had to go through and zero out
all of the elements of that array.
I note in the documentation: "This method is an O(n) operation, where n
is Count":
http://msdn2.microsoft.com/en-us/library/dwb5h52a.aspx
Sounds to me as though List.Clear() definitely does clear each item in
the array.
Pete