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

The Archive Base Latest Questions

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

I found out that if my application has much free memory available it uses

  • 0

I found out that if my application has much free memory available it uses more memory than it needs. I heard that this behavior is common for all Java applications but it’s not acceptable for me.

So the question is how can I force Java to use less memory?

I know that I can call System.gc() manually every few seconds, but is it alright to do so and are there any other methods?

P.S. my application is updated regularly on production server and I need to monitor memory usage for some leaks and so on (generally there are no leaks but if one appears I should see it as fast as possible), and also I need to predict the time when I should upgrade my hardware. All these things are very hard to do if jvm unpredictably changes its memory hunger. So the only thing I want is to force jvm to be predictable in memory usage (if number of users doubles memory should doubles too)

  • 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-29T04:04:55+00:00Added an answer on May 29, 2026 at 4:04 am

    I found out that if my application has much free memory available it uses more memory than it needs. I heard that this behavior is common for all Java applications but it’s not acceptable for me.

    It depends on what you mean “more memory than it needs”. If you mean, more than the minimum memory to represent your application’s objects, then you are correct.

    It is standard behavior that Java uses more memory than the bare minimum that it could theoretically get away with. “Worse still”, most JVMs don’t give memory back to the OS … even if that memory has been freed by the GC. Both of these properties are necessary for efficient operation of a general purpose garbage collector.

    If this is unacceptable to you, you should not be using a garbage collected language. Use C or C++. (But also be aware that it is unusual for C / C++ memory allocators to be able to give memory back to the OS either … even if the implementation allows it.)


    The positive side of this is that Java (and in fact any GC’ed language) will actually run better if you give it plenty of memory. Modern GC’s work more efficiently as the ratio of garbage to non-garbage increases, and a larger heap makes that happen. (Of course, you can go too far, especially if the application is competing with other things for real memory.)


    As other answers said, calling System.gc() does not help. It is unlikely to result in any memory being given back. Worse still, you’ll most likely run the GC when the garbage level is too low for efficient operation, so you will be increasing CPU time for no benefit.


    Concerning your “PS”:

    1. I don’t think there is a way to (reliably) detect the existence of a memory leak … apart from monitoring memory usage trends.

    2. I don’t think there is a way to (reliably) predict when you will new hardware … apart from monitory memory usage (and other) trends.

    3. I don’t think there is a way to force you application’s memory usage to be proportional to the number of users … apart from designing / coding your application so that it scales in the way you want.

    On the other hand, you could say the same thing about a C / C++ application.

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

Sidebar

Related Questions

Hi I found out that my application causes some errors which are logged in
I found out that HTML form supports only two enctype types. They are application/x-www-form-urlencoded
After I uploaded my application created using cakephp, I found out that I had
I have an application that requires .Net. I have found out how to check
I found out that build time of C# solution with many projects gets much
I have recently found out that the future of Qt has become uncertain as
I found out that I can use a different theme in an C# WPF
I found out that the FormWizard only __init__ 's once, when the url is
Just found out that the video output of the iPad is not a system
I found out that in order to open a Gmail compose screen you'd have

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.