my dog learned polymorphism*
The moose likes Beginning Java and the fly likes setting heap size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "setting heap size" Watch "setting heap size" New topic
Author

setting heap size

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375
I know we can set -Xmx256m kind stuff in the eclipse run configuration panel's arguments/ Question --

1. what's the default heap size for each application ?

2. when you set "-Xmx256m", does it mean you allocate that much memory for your application ? Then don't you need to consider what's the memory of your PC ? what if you set -Xmx1024m but you don't have 1024M memory ? Plus, even if you have 1024M memory, if you set -Xmx 512m, then does it mean other application can only share the remaining 512m ?

3. in a production env, if each application set -Xmx512m, then potentially each of them consumes so much memory, is that true ?

Fundamentally, I want to understand when you do "java myapp -Xmx512m", does it mean you allocate at most 512M to "myapp" only ?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

It means that the Java heap can grow to that size, at maximum, for that application. It will generally start smaller, and will grow as needed up to that size, but no larger. The maximum amount used by your application will actually be larger, because the Java heap size doesn't count the space taken up by the VM implementation, etc.

In any case, do you understand the idea of "virtual memory"? All modern operating systems effectively use your disk space as extra RAM, so that the total amount of memory needed by all running programs can actually be larger than the amount of physical memory you have. How well the computer handles that situation depends on the OS and on the hardware, of course.


[Jess in Action][AskingGoodQuestions]
 
GeeCON Prague 2014
 
subject: setting heap size