Skip to content

SortedList allocates memory due to boxing of TKey #100406

Closed
@PetrAltman

Description

@PetrAltman

Description

SortedList<TKey, TValue> with struct TKey allocates memory due to boxing of TKey.

Configuration

Net 8,0

Analysis

Several methods in SortedList (e.g., Add, Remove, IndexOf) verify that the key is not null by invoking ArgumentNullException.ThrowIfNull(key);. ThrowIfNull expects an object parameter, causing TKey to be boxed when it is a struct type. This behavior should be avoided for struct types. It might be beneficial to add a generic overload to ArgumentNullException that does not allocate memory for struct types. This change could be useful as similar scenarios might occur in other generic classes within .NET.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions