Memory Use In Java


When you run a Java application, there is usually a fixed maximum amount of memory which is available. This is usually 64 megabytes of memory.

So if you run a java program from the command line like this, the program can use a maximum of 64 megabytes of memory (this is the default).

java -jar jpedal.jar

Sometimes, you need more memory. So there is a useful Java option (-Xmx) to increase the maximum memory available. The format is slightly fiddly so best shown with an example which tells Java to use a maximum memory of 128 megabytes instead

java -Xmx128M -jar jpedal.jar

The number value comes straight after the -Xmx flag and then the M tells Java the figure means megabytes (which is the most common setting you would use). The memory needs to be available – if it is not the program will fail to run.

So if you need a little more memory, just add this flag to your Java command.

I was asked to explain memory usage in a (hopefully) non-technical way which led to this short article. If there is anything Java/PDF related which you would explained, please drop us a line and we will try to help.


About the Author:
Mark Stephens runs IDRsolutions, developing the JPedal PDF library in Java, and shares his thoughts on Java, PDF, the Business of Software and Mediaeval History at .