Dictionary<TKey,TValue>.TrimExcess Method

Definition

Overloads

TrimExcess(Int32)

Sets the capacity of this dictionary to hold up a specified number of entries without any further expansion of its backing storage.

TrimExcess()

Sets the capacity of this dictionary to what it would be if it had been originally initialized with all its entries.

TrimExcess(Int32)

Sets the capacity of this dictionary to hold up a specified number of entries without any further expansion of its backing storage.

public:
 void TrimExcess(int capacity);
public void TrimExcess (int capacity);
member this.TrimExcess : int -> unit
Public Sub TrimExcess (capacity As Integer)

Parameters

capacity
Int32

The new capacity.

Exceptions

Remarks

This method can be used to minimize the memory overhead once it is known that no new elements will be added.

TrimExcess()

Sets the capacity of this dictionary to what it would be if it had been originally initialized with all its entries.

public:
 void TrimExcess();
public void TrimExcess ();
member this.TrimExcess : unit -> unit
Public Sub TrimExcess ()

Remarks

This method can be used to minimize memory overhead once it is known that no new elements will be added to the dictionary. To allocate a minimum size storage array, execute the following statements:

dictionary.Clear();
dictionary.TrimExcess();

Applies to