I have question regarding how memory is managed for strong type Generics
List ints1 = new List();
ints1.Add(1); ints1.Add(2); ints1.Add
Memory management for generics (Generic collections) is exactly the same as for non-generic types.
Your ints1
list uses an array under the covers. So it is the same as for ints2
(when it has been corrected). In both cases a block of memory on the Heap is holding the int
values.
The List<>
class consists of an array, a int Count
and an int Capacity
property. When you Add() an element Count
is incremented, when it passes Capacity
a new array is allocated and the contents are copied.