First I will explain how I thought memory works in Java and then my problem. Please correct me if I am wrong.
From the docs on the “java” command:
To me, this means that I start out with 2MB of RAM available to my program. If my program requires more that 2MB, then the JVM will add more memory for use in my program, until the 64MB max is reached.(This is all assuming default values).
This line from the JVM spec seems to confirm this:
In a program that I am working, I am trying to open a file for viewing. I am doing some manipulation with the data in a StringBuilder before I view the file. The amount of memory required for the file is 11MB. When I try to run with this file I get an OutOfMemoryError. The only way I can get this file to work is if I set the initial heap size to a value larger than 11MB, ie if I pass -Xms20m gives me enough memory. This seems to contradict the statements above from the spec that the heap is supposed to expand as required.
I tried to search to see if there is a bug, but couldn’t find anything.
Am I totally off base here? Is there something I have to do programatically to access more memory? I would rather not have to pass that memory argument to the JVM.
Thanks.
