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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:00:54+00:00 2026-05-11T14:00:54+00:00

I have a question regarding the JVM memory management (at least for the SUN’s

  • 0

I have a question regarding the JVM memory management (at least for the SUN’s one).

I would like to know how to control the fact that the JVM send the unused memory back to the OS (windows in my case).

I wrote a simple java program to illustrate what I expect. Run it with -Dcom.sun.management.jmxremote option so that you can also monitor the heap with jconsole for example.

With the following program:

package fr.brouillard.jvm;  import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.List;  public class MemoryFree {     private BufferedReader reader = new BufferedReader(new         InputStreamReader(System.in));     private List<byte[]> usedMemory = new LinkedList<byte[]>();     private int totalMB = 0;     private int gcTimes = 0;      public void allocate(int howManyMB) {         usedMemory.add(new byte[howManyMB * 1024 * 1024]);         totalMB += howManyMB;         System.out.println(howManyMB + 'MB allocated, total allocated: ' +                 totalMB + 'MB');     }      public void free() {         usedMemory.clear();     }      public void gc() {         System.gc();         System.out.println('GC ' + (++gcTimes) + ' times' );     }      public void waitAnswer(String msg) {         System.out.println('Press [enter]' + ((msg==null)?'':msg));         try {             reader.readLine();         } catch (IOException e) {         }     }      public static void main(String[] args) {         MemoryFree mf = new MemoryFree();         mf.waitAnswer(' to allocate memory');         mf.allocate(20);         mf.allocate(10);         mf.allocate(15);         mf.waitAnswer(' to free memory');         mf.free();         mf.waitAnswer(' to GC');         mf.gc();         mf.waitAnswer(' to GC');         mf.gc();         mf.waitAnswer(' to GC');         mf.gc();         mf.waitAnswer(' to GC');         mf.gc();         mf.waitAnswer(' to exit the program');          try {             mf.reader.close();         } catch (IOException e) {}     } } 

The internal heap is free once the first GC is done (what is expected) but the memory is only sent back to the OS starting from the third GC. After the fourth, the full allocated memory is sent back to the OS.

How to setup the JVM to control this behaviour? In fact my problem is that I need to run several CITRIX clients sessions on a server, but I would like the running JVMs on the server to free the memory as soon as possible (I have only few high consuming memory functions in my application).

If this behaviour cannot be controlled, can I let it like this and increase instead the OS virtual memory and let the OS using it as it wants without big performance issues. For example, would there be issues to have 10 java process of 1GB memory (with only 100MB real allocated objects in the heap) on a 4GB server with enough virtual memory of course.

I guess that other people already faced such questions/problems.

Thanks for your help.

  • 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. 2026-05-11T14:00:55+00:00Added an answer on May 11, 2026 at 2:00 pm

    To control return of heap to the OS, from Java 5 onward, use the -XX:MaxHeapFreeRatio option, as described in the tuning guide.

    If you feel your question is meaningfully different from this one, please point out how.

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

Sidebar

Related Questions

I have a question regarding django templates and html frameset's. I would like to
I have question regarding shared memory segmentation in c using POSIX system calls. Is
I have question regarding the service and activity. I have one service which calls
I have question regarding about finding subview using '.tags' in one UIView. for (UIView
I have a question regarding a platform I'm developing called e-cidadania (GPL). One of
I would have question regarding web services. Let's say I have webservice client that
I have question regarding the CreateWindowEx function. I have 2 windows, a main one
I have one question regarding standard WPF DataGrid in .NET 4.0. When I try
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I 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.