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

  • Home
  • SEARCH
  • 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 8872425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:13:11+00:00 2026-06-14T18:13:11+00:00

Given the opportunity to rewrite, I would, but anyway, the code as it stands:

  • 0

Given the opportunity to rewrite, I would, but anyway, the code as it stands:

List<string> foobar;

Then we add a bunch of strings to foobar.

At count=16777216, we hit an out of memory limit.

My understanding is that each string would be a different size. Indeed looking at the data (not my data), most are 2 or 3 characters.

what is the max limit of data into list in c#? indicates that the max limit is:

The maximum number of elements that can be stored in the current
implementation of List is, theoretically, Int32.MaxValue – just
over 2 billion.

However:

In the current Microsoft implementation of the CLR there’s a 2GB
maximum object size limit. (It’s possible that other implementations,
for example Mono, don’t have this restriction.)

In my example, I have, what, 16 million results * a few bytes? Task manager shows about a gig being used, but I have 8 gigs of RAM.

16777216 (2^24) seems like a fairly specific value – suspiciously like a limit, but I can’t find any documentation anywhere to a) back this up or b) find a way around it?

Any help would be appreciated.


Some code:

List<string> returnList = new List<string>();
SqlDataReader dr; //  executes a read on a database, have removed that part as that bit works fine

  if (dr.HasRows)
  {
      while (dr.Read())
      {
          returnList.Add(dr.GetString(0).Trim());
      }
  }

That’s the simplified form, I now have some try/catch for the OOM Exception, but this is the actual code that’s giving me grief.

  • 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-06-14T18:13:12+00:00Added an answer on June 14, 2026 at 6:13 pm

    If you’re trying to use very large lists in 64 bit environments you need to enable large objects in the application configuration.

    http://msdn.microsoft.com/en-us/library/hh285054.aspx

    The OOM is likely due to the way Lists/ArrayLists allocate memory, which I believe is each time their boundary is reached, they attempt to double in size. The list cannot double from 2^24. You could theoretically maximize your list size by pre-specifying a size. (I.e. 2GB)

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

Sidebar

Related Questions

I would also like to have an opportunity to add/modify HTTP GET headers, but
For the python program I am writing I would like to give the opportunity
Given a MySQL table of real estate data, I would like to generate a
Given the following code: $(.force-selection).blur(function() { var value = $('matched-item').val(); //check if the input's
Given the jQuery dropdown plugin below. Is there a way to add a method
When sharing an image in an iPhone, we are given an opportunity to pick
In company that I work for, I was given the opportunity to write an
I am creating an app where users will be given the opportunity to register
I would like to give the opportunity to post a comment to my website
Given this C API declaration how would it be imported to C#? int _stdcall

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.