Destroying collections is done in two steps. First the elements of the collection are destroyed, then the collection itself is destroyed. This discussion assumes that both collections and collection elements have been created with the new operator and thus occupy heap memory.
Most of the example programs which manage collections in this chapter use the following two statements to destroy collections.
collection->DeleteAll(); delete collection;
TIteratorOver<TCollectibleLong>* element = collection->CreateIterator(); for (TCollectibleLong* number = element->First(); number != NIL; number = element->Next(), i++) { delete element; }
The previous section "Removing elements" also covers aspects of destroying collections related to individual collection elements.