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 331789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:48:25+00:00 2026-05-12T09:48:25+00:00

I’m troubleshooting an OutOfMemory exception in my .NET 2.0 Windows Service application. To understand

  • 0

I’m troubleshooting an OutOfMemory exception in my .NET 2.0 Windows Service application. To understand the issue better I began by writing a simple .NET WinForm test app that generates an OOM Exception by building an ArrayList until an OOM Exception is thrown. The exception is caught and logged and I can click on a form button to run the OOME again. The strange thing I found was on the 4th run, the amount of memory consumed before the next OOME was roughly half. The results listed below are consistent every time I run this. Eyeballing TaskManager also confirms the behavior. Unfortunately, Perfmon froze up when trying to get better stats. Can someone explain why the memory limit is lowered after 3 runs? My understanding of GC is fairly shallow. You can also see I ran a GC.Collect() after a few more runs but it didn’t help with the lowered limit.

UPDATE: I also found a big difference using a const string vs a new object for each arraylist item. Code is simply:

const string TEST_TEXT = "xxxxxxxxxx";
ArrayList list = new ArrayList();
while (true)
{
    list.Add(TEST_TEXT);
}

Start Loop: memory 10,350,592

  • OOM Exception Thrown
  • Array Size: 134,217,728

End Loop: memory 550,408,192

Start Loop: memory 550,731,776

  • OOM Exception Thrown
  • Array Size: 134,217,728

End Loop: memory 551,682,048

Start Loop: memory 551,813,120

  • OOM Exception Thrown
  • Array Size: 134,217,728

End Loop: memory 551,772,160

Start Loop: memory 551,903,232

  • OOM Exception Thrown
  • Array Size: 67,108,864

End Loop: memory 282,869,760

Start Loop: memory 283,004,928

  • OOM Exception Thrown
  • Array Size: 67,108,864

End Loop: memory 282,910,720

GC.Collect manually triggered

Start Loop: memory 14,245,888

  • OOM Exception Thrown
  • Array Size: 67,108,864

End Loop: memory 283,344,896

  • 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-12T09:48:25+00:00Added an answer on May 12, 2026 at 9:48 am

    Here are several points which, taken together, hopefully will give you enough information to answer your question:

    • In spite of it’s name, OutOfMemory exceptions are just as likely to mean you are out of Address Space as physical RAM.
    • GC.Collect does not collect all outstanding RAM. Garbage collections in .Net are non-deterministic, meaning there is no way to force the runtime to clean up all your RAM.
    • The garbage collector in .Net is generational, meaning when an object survives collection it moves up to a higher generation, making it even less likely to be collected.
    • By the time your OutOfMemory exception is thrown, your array has probably already survived a few collection attempts or was even moved to the LargeObjectHeap.
    • Array sizes are fixed. To add a new element to an array you must completely re-allocate the array. (You might get better test results using a structure like a list).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.