Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6375333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:36:05+00:00 2026-05-25T01:36:05+00:00

Given a list: List<myType> myList = new List<myType>(); with the collection contents modified at

  • 0

Given a list:

List<myType> myList = new List<myType>();

with the collection contents modified at runtime….

To clear the list, I have seem examples which suggest using

myList = new List<myType>();

rather than

myList.Clear();

I can think of a number of reasons why I would prefer one over the other but are there any other good benchmarks or guidelines as to when one method is preferable to the other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:36:06+00:00Added an answer on May 25, 2026 at 1:36 am

    If a list is large (80 kilobytes or more), then it’s going to be stored on the large object heap. The official guidance for the LOH is to re-use objects there as much as possible in order to reduce heap fragmentation. The LOH isn’t compacted like the regular heap is.

    For smaller lists, I’ve found that it’s often faster overall to create a new one than it is to call Clear. This isn’t always true, so you’re probably best off testing it both ways in your applications.

    If you call Clear, it just sets all of the items in the list to their default values and sets Count to 0. It does not change the list’s capacity. So calling Clear will not change the amount of memory allocated to the collection. If you want to clear the list and reduce its size, call Clear and then TrimExcess.

    One problem you’ll run into if you’re not careful is aliasing. If you have multiple objects that refer to the same list, creating a new list doesn’t remove those other references. So then you end up with two lists. Just something to think about.

    All told, I don’t think there’s a particular “best practice” for this. I’ve found that sometimes it’s good to use Clear and sometimes it’s best to allocate a new list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query regarding to find out which is day (in given list)
Given: var detailList = new List<DetailItem>(); Where: class DetailItem { string A; MyType B;
Circumstances I have a procedure which will construct a matrix using the given list
Given a list, how would I select a new list, containing a slice of
Given a list of elements like so: int[] ia = new int[] { -4,
Given List<double> x1 = new List<double> { -0.2718, -0.2240, -0.1275, -0.0810, 0.0349, -0.5067, 0.0094,
I have a Hibernate validator that validates a field against a given list of
I have a function that returns a comparison matrix from a given list: def
Given: List<int> list = new List<int> { 1, 2, 3, 4, 5, 6, 7,
I have a given list of URL's, and i make an HTTP web request

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.