Reputation: 21194
Is there a minimum -Xmx setting for Oracle's JVM? It looks like -Xmx2M does provide the application with more than 2 MB of heap size, as the Java Memory MX bean tells me it allocates like 10 MB...
Is there a minimum under which the JVM silently ignores the Xmx setting?
Upvotes: 0
Views: 294
Reputation: 3481
For jvm to start minimum 2mb of heapsize is required. You can set heap size to 0 bytes, but jvm will not start. And maximum heap size recommended is 1/4 of total ram.
Upvotes: 0
Reputation: 533442
If I run
public static void main(String[] args) {
System.out.println("Heap size is " + Runtime.getRuntime().totalMemory() / 100000 / 10.0 + " MB");
}
with -mx8m
on Java 7 update 25 64-bit I get
Heap size is 8.0 MB
but if I run with -mx2m
I get
Heap size is 3.2 MB
So it does appear you get slightly more heap than you asked for for very small sizes. However, even for a small mobile device I wouldn't be worrying about every last MB because the JVM itself is much larger (can be over 100 MB of shared memory, thread etc)
i.e. if you can't spare a few MB, you won't be able to run the JVM anyway.
Upvotes: 2