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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:54:32+00:00 2026-05-27T04:54:32+00:00

I have been looking in google for a solution to my problem but no

  • 0

I have been looking in google for a solution to my problem but no success.
I have a “near real-time” application that checks available memory from time to time and notifies the user in case there is no less than 10% free memory in the system.
I am using the following code to do so:

double free = Runtime.getRuntime().freeMemory();
double total = Runtime.getRuntime().maxMemory();
double freeMemoryProc = (free / total) * 100;
if (freeMemoryProc <= 10) {
   // Warn user...
}

This bit of code is working fine most of the time but is giving me erroneous messages when the GC did not kick in time to collect all unused memory.

Questions:

  • Am I right when saying that freeMemoryProc is not a true measurement as it depends on when the GC kicks in?

  • Is there a better way (preferably independent from GC) to calculate the amount of available memory for a my application?


Related question (did not help)

Obtaining memory available to JVM at runtime

Thanks in advance,
Regards.

  • 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-27T04:54:32+00:00Added an answer on May 27, 2026 at 4:54 am

    Am I right when saying that freeMemoryProc is not a true measurement as it depends on when the GC kicks in?

    Yes … sort of. It is a measure of the amount of memory that is not currently allocated, not of memory that could be allocated if necessary.

    Is there a better way (preferably independent from GC) to calculate the amount of available memory for a my application?

    There is no way to do this that is independent of the garbage collector. In general, the only way that you can tell if memory that is currently allocated to objects is “in use” in the sense that it is not uncollected garbage is … to run the garbage collector.

    The best you can do is to capture the memory usage immediately after a garbage collector run, and hope that the pattern of memory usage is relatively smooth.

    Note that running the GC simply to find out how much memory is left is a bad idea from a performance perspective … and especially in a near real-time application. (But I guess you already know that!)

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

Sidebar

Related Questions

I have been looking around ocn Google and Stackoverflow but haven't found what I
have been going through here and google looking for a spellcheck solution. I see
I have been looking for a regular expression with Google for an hour or
Have been looking at the MVC storefront and see that IQueryable is returned from
I have been looking all over google to find some answers to my questions
I have been looking all over google to find what the hex output of
So I have been looking at Google Maps and they have the feature of
I have been looking in google and documentation function like plogis , dlogis ,
I have been looking for cloud computing / storage solutions for a long time
I have been looking into IKVMing Apache's FOP project to use with our .NET

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.