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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:45:08+00:00 2026-05-14T16:45:08+00:00

I need to refactor my project in order to make it immune to OutOfMemory

  • 0

I need to refactor my project in order to make it immune to OutOfMemory exception.

There are huge collections used in my project and by changing one parameter I can make my program to be more accurate or use less of the memory…

OK, that’s the background. What I would like to do is to run the routines in a loop:

  1. Run the subroutines with the default parameter.
  2. Catch the OutOfMemory exception, change the parameter and try to run it again.
  3. Do the 2nd point until parameters allow to run the subroutines without throwing the exception (usually, there will be only one change needed).

Now, I would like to test it. I know, that I can throw the OutOfMemory exception on my own, but I would like to simulate some real situation.

So the main question is:
Is there a way of setting some kind of memory limit for my program, after reaching which the OutOfMemory exception will be thrown automatically?
For example, I would like to set a limit, let’s say 400MB of memory for my whole program to simulate the situation when there is such an amount of memory available in the system.
Can it be done?

  • 1 1 Answer
  • 1 View
  • 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-14T16:45:08+00:00Added an answer on May 14, 2026 at 4:45 pm

    I’d like to suggest another way of looking at this. You don’t necessarily have to run out of memory. You just need to monitor the amount of memory used, and compare it to the total system memory. Perhaps something like GC.GetTotalMemory will be useful here to see how much memory your application is using. Then perhaps this article will help with getting the total amount of physical RAM available on your system.

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

Sidebar

Related Questions

I am just embarking on my first large-scale refactor, and need to split an
Need a function that takes a character as a parameter and returns true if
I need to implement a finite-state-machine in order to keep track of a few
I feel the need to refactor my old CF5 based code into CFC's. We
I am probably going to need to refactor in two steps since I'm still
We have a project that is starting to get large, and we need to
Need a way to allow sorting except for last item with in a list.
Need to an expression that returns only things with an I followed by either
Need to locate the following pattern: The letter I followed by a space then
need ask you about some help. I have web app running in Net 2.0.

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.