Reputation: 3085
For the following no-op code,
public class a {
public static void main(String args[]) throws Exception{
Thread.sleep(100000);
}
}
If I run it on a 64-bit jvm, through "top" I can see that it uses 2GB virtual memory. What is taking up that virtual memory? This example may be weird, but we do see some production code that uses a lot of virtual mem so that it exceeds ulimit -v
Thanks Yang
Upvotes: 3
Views: 300
Reputation: 533492
When you start a Java application it creates its heap (to its maximum size) on start up. The default size for recent Sun/Oracle JVMs is 1/4 of your main memory. This sounds wasteful, except all it does is reserve address space. Given each application has its own address space, this doesn't matter much. (unless you have a 32-bit JVM with limited address space)
Upvotes: 0
Reputation: 69342
Virtual memory does not mean that it is actually allocated and being used. It simply means it has that much currently addressable for use if need be.
Upvotes: 4