aspose file tools*
The moose likes Java in General and the fly likes Unused java memory is not released to OS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Unused java memory is not released to OS " Watch "Unused java memory is not released to OS " New topic
Author

Unused java memory is not released to OS

R. Praveen Kumar
Greenhorn

Joined: Dec 06, 2012
Posts: 9
Unused java heap memory is not getting released to OS even if i use the following VM options:
-XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=10

Still when more than 80 percent of heap memory is free, it is not getting released to OS

Details:
Java HotSpot(TM) 64-Bit Server VM (1.5.0_15-b04, mixed mode)
ParallelGC (otherwise known as throughput collector which is the default collector in server class VM)
i specified -Xms50M and -Xmx1000M as jvm arguments
OS: windows 7 professional (8 GB memory 64 bit OS)

tried using serialGC, with those heapfreeratio jvm args, still when more than 80 percent of heap memory is free, it is not getting released to OS

whether "AggressiveHeap" "UseAdaptiveSizePolicy" jvm options (which i didnt specify to jvm) has anything to do with this.
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1059
    
  10

Any memory allocated to the JVM by the OS is only released back to the OS when the JVM exits. The garbage collector only make memory re-usable by the JVM and not by the OS.
R. Praveen Kumar
Greenhorn

Joined: Dec 06, 2012
Posts: 9
Hi Richard, thanks for your reply. If what you said is true, then what is the purpose of -XX:MinHeapFreeRatio -XX:MaxHeapFreeRatio jvm options.

For your reference: http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1059
    
  10

R. Praveen Kumar wrote:. If what you said is true, then what is the purpose of -XX:MinHeapFreeRatio -XX:MaxHeapFreeRatio jvm options.l


In the context of releasing memory back to the OS they have no purpose. In the context of the latest garbage collection algorithm I am not expert enough to provide an authoritative answer.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

I don't think it's true that the JVM never releases memory back to the OS while it's running. Rather, it will do so on its own terms according to whatever algorithm is built in to that particular JVM implementation and whatever command line args we've given it to adjust that algorithms' parameters. It's just another one of the JVM's internal administrative tasks, like thread scheduling or physical memory layout of objects that's largely unspecified and in general unpredictable.
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1059
    
  10

OK Jeff, I will qualify my response. In over a decade of my involvement with Java starting with jdk1.0.1 and going though to 1.7 using Sun implementations, Oracle implementations and IBM implementations I have never seen a JVM implementation that released memory back to the OS and have never seen a statement that said it did. You may be right in that it may be unspecified behaviour that the JVM implementers are free to handle as they wish but I have never seen an implementation that releases the memory.


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Richard Tookey wrote:I have never seen a JVM implementation that released memory back to the OS and have never seen a statement that said it did.


Hmmm... I may be mis-remembering then, but I thought I had seen both documentation and behavior indicating that at least some implementations do give some back to the OS in some circumstances.

Maybe you're right though and I'm just losing my marbles.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I'm pretty sure that the JVM I used to use at work (on the IBM i machine) used to return unused memory to the operating system.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

FWIW, a quick google search for when does JVM return memory to OS gave this, which has a comment (presumably from somebody at Sun) saying, "The HotSpot JVM already will release memory back to the operating system if it is not needed for live Java objects."

Also, here it says, "To complicate matters further, the JVM may choose not to release unused memory back to the operating system," which suggests that it may also choose to release it back to the OS.

Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1059
    
  10

Looks like I am very very wrong so I apologize to all especially to the OP.
R. Praveen Kumar
Greenhorn

Joined: Dec 06, 2012
Posts: 9
Thank you all..

i think ParallelGC will ignore those options, it just dynamically resizes young and old generations based on "pause time" and "throughput" goals.

blogs.oracle.com/jonthecollector/entry/it_s_not_magic

And yes the JVM will release memory back to OS if it is able to meet those "pause time" and "throughput" goals. JVM tries to achieve these goals with least heap memory possible

all the above are true for ParallelGC.. didnt try with other GCs (like SerialGC, CMS,... )

and Richard, its ok, no need to apologize to anyone, all are here to learn :-)
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5

I have never seen a JVM implementation that released memory back to the OS


I (many years and versions ago) once played around with several Java versions and with some I was able to detect their returning memory to the OS, whereas with others not.
It depended on the Java version and not the platform (Windows or Linux).
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Richard Tookey wrote:Looks like I am very very wrong so I apologize to all especially to the OP.


No apologies necessary. We all learned something, and you motivated me to do a little research to confirm something I only thought I knew.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2377
    
  28

There are differrences between how memory is managed when you use the client VM vs Server VM

From the FAQ on Java Hotspot VM

What's the difference between the -client and -server systems?
These two systems are different binaries. They are essentially two different compilers (JITs)interfacing to the same runtime system. The client system is optimal for applications which need fast startup times or small footprints, the server system is optimal for applications where the overall performance is most important. In general the client system is better suited for interactive applications such as GUIs. Some of the other differences include the compilation policy,heap defaults, and inlining policy.


I am guessing here, but I'm pretty sure that the Client VM will be more inclined to release memory back to the OS (and hence have a smaller footprint), whereas a server VM will be more inclined to keep the memory to itself (and hence improve performance) Allocation of memory at the OS level is not cheap, and if you have an application that is continuously running, it's better to keep the memory to yourself and reuse it. In OS that provide virtual memory, memory can get fragmented too just like your disk can get fragmented (although defragging the memory is much cheaper), and it's better to get one contiguous block of memory. The downside of keeping memory, is of course that the application would hog up system resources, and also startup time is also increased.

Server applications that are built in languages that do not provide GC, it's not uncommon to implement your own pooling of objects. C++ Std library had introduced an allocator module that allowed you to customize allocation mechanism. And the biggest reason for this was so you can implement your own custom pooling easily. Generally, you don't do pooling of objects in Java because the JVM is pooling the memory for you, so it's a moot point

IMO, at the end of the day, if you are building a server app, you shouldn;t be looking at the memory used by the JVM at the OS level. WHether or nor the JVM is releasing memory back to the OS is a red herring. What matters more is how much of your heap is allocated.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unused java memory is not released to OS