how to set memory used by JVM.
Who knows how does the JVM set the physical memory it wanted? Or is there any method to enlarge the JVM memory at runtime?
When I use "Java xxx" to run a small class the Runtime.totalMemory() report a small total memory.
And when I use "java yyy" to run a large class the method will report a large total memory.
This way it seems that the JVM will determine the total memory according to the run time work, but when I run a very large work with a lot of memory used the JVM will report a out of memory exception. But when this happened the actual physical memory of my computer still have millions of byte unused.
Is that a bug of JVM or something else?
Who knows? Please tell me.
[725 byte] By [
cm_java] at [2007-9-26 1:45:22]

Have a look at the documentation:
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/java.html
You can set the initial size of the memory allocation pool using the command line option -Xms and the maximum size using -Xmx. For example:
java -Xms64m -Xmx128m MyClass
will start the JVM with a pool of 64 MB which may grow to 128 MB before you get an OutOfMemoryError.
regards
Jesper
I found this very useful information here after finding my application giving an OutOfMemoryError when totalMemory reached 64M.
Apparently the heap maximum defaults to 64M!
That is a bit unfriendly on a machine with 384M available.
Thanks!
P.S. I don't see why should there be *any* memory limit applied to the JVM?
> P.S. I don't see why should there be *any* memory
> limit applied to the JVM?
Everything has an absolute limit in computing.
The language definition implies some memory limitations on the language, for instance the maximum size of an array.
The memory limits in java are there (probably) for stability purposes. With a fixed limit an application can not run out of control and eat all the memory on a system.