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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:55:13+00:00 2026-05-27T11:55:13+00:00

There a quite a few questions in SO related to the OutOfMemoryError: Java Heap

  • 0

There a quite a few questions in SO related to the “OutOfMemoryError: Java Heap” error, but reading over them, most seem to discuss how to increase the heap size or profiling the app and detecting memory leaks.

I’m working on a project, that invovles analyzing the cost of a branch and bound algorithm. For input small input sizes, the potential number of solutions to search grows at O(n!). At a certain input size, n, I’ve encountered the “OutOfMemoryError” because the parial solutions are kept in a priority queue until ready to be treated, and the huge number of partial solutions in the queue fills up the memory. So, I know I don’t have a memory leak, and I don’t necessarily want to increase the heap size.

What I’d like to do is simply detect when the memory is nearly full, then give the user a message that tells them what’s going on and why the program is exiting (it’s not necessary the program keep functioning at this point). Is there a way to do this? I have looked at the java.lang.management package, but it doesn’t make much sense to me, and I’ve had difficulty finding decent example code. Any explanation or example code is appreciated.

  • 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-27T11:55:14+00:00Added an answer on May 27, 2026 at 11:55 am

    What I’d like to do is simply detect when the memory is nearly full, then give the user a message that tells them what’s going on and why the program is exiting (it’s not necessary the program keep functioning at this point).

    That’s difficult. Mostly because free memory is not really known before a garbage collection takes place, and a serious garbage collection usually only happens just before you run out.

    What you can do is explain why the program has crashed after the fact: Eclipse does this for example. You can catch the OutOfMemoryError just like any other Throwable, and show your message:

     try{
          heavyLifting();
     }
     catch (OutOfMemoryError e){
        showAMessage();   
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I looked through the related questions, there were quite a few but I don't
On SO, there are quite a few questions about performance profiling, but I don't
I know there are quite a few questions concerning access violations, but I have
I know there are quite a few text-to-array questions out there, but I am
Now I know there are quite a few questions regarding this but in general
There's quite a few questions on Stack Overflow about id vs class but these
I looked at quite a few of the related questions and I must be
I am aware that there were similar questions in past few years, but after
I know there are a few questions floating around here on the subject, but
I know there are quite a few questions on this already and i've looked

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.