File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Releasing memory to OS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Performance
Bookmark "Releasing memory to OS" Watch "Releasing memory to OS" New topic
Author

Releasing memory to OS

Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
Hello,
I have an issue of System.gc() releasing memory only for the current JVM and not to the OS and hence I am getting High physical memory usage alert in my machine.
To ellaborate once the current JVM has taken up the max memory allocated for it using the command -Xmx1024m, when there is memory requirement garbage collector is releasing the memory only within the JVM and not to OS and hence the task manager is showing high usage of memory by the current JVM.Can anyone help me out in fixing this issue
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
1. I dont think there is any way to force the JVM to release memory to the OS.
2. If you don't want the JVM to use up to 1024m, why are you running with that parameter?
3. If the application required huge amounts of memory sometimes but can run with much less most of the time, can it be redesigned?
4. What operating system is this? How much physical memory does it have?
Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

The Windows version of Sun's JVM doesn't ever give memory back to Windows. But this is not true of all JVMs. For example IBM's JVM for the iSeries system does give back memory to the operating system. So if you can't fix the problem with your software, you could change your hardware.
u johansson
Ranch Hand

Joined: Dec 27, 2005
Posts: 47
Never call System.gc(). Sun has spent millions of dollars to take memory management off the back of the programmer. Why are you trying put it back on?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Paul Clapham:
The Windows version of Sun's JVM doesn't ever give memory back to Windows.


Are you sure? I thought at least the Java 5 VM does, if it is configured correctly.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
Never call System.gc().

I can't agree with that - Never is too strong. If my application has just generated a display that I know my user will take some time to absorb, it is an ideal time to call gc().
u johansson
Ranch Hand

Joined: Dec 27, 2005
Posts: 47
No, William Brogden , you, or nobody else, should never call gc().

It's a big mistake. Sun has spent millions so you don't have to bother about memery management. Never call gc().
u johansson
Ranch Hand

Joined: Dec 27, 2005
Posts: 47
Look at this for example

http://www-128.ibm.com/developerworks/java/library/j-jtp01274.html
Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
No if I dont run with the parameter -Xmx1024 it will throw out of memory exception
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Are you sure it is the heap that is taking the memory?

Use a 1.5 JDK and start jconsole to see what part of the JVM is taking up the memory...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Originally posted by Ilja Preuss:


Are you sure? I thought at least the Java 5 VM does, if it is configured correctly.
You could be right about that. I don't see any reference to it in the "new features and enhancements" document but that doesn't mean it isn't the case.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Releasing memory to OS