Best way to Dispose List<T>

T.Zacks 3,986 Reputation points
2021-04-03T09:12:42.557+00:00

i did this way....is it good approach or not ? i use TrimExcess() is it good practice. please guide me. thanks

public static void ListDispose<T>(this List<T> _list)
        {
            if (_list != null)
            {
                _list.Clear();
                _list.TrimExcess();
                _list = null;
            }
        }
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,246 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,726 Reputation points
    2021-04-03T09:28:36.783+00:00

    You can find some threads in MSDN forums archives, like :
    What List TrimExcess() does and when to use it