Search code examples
javajvmramjvm-arguments

JVM - How much RAM should I allocate


I didn't find a suggestion on how much RAM I actually should allocate to the JVM.

Assuming that my computer has 4GB RAM and runs Windows 10. I nearly only use Java Applications on it. With how much RAM should I start the JVM? The system needs RAM for itself too, so in my logic, I should not allocate 4 GB even if that is possible.

This isn't a black/white question, I just want to have an idea and how to come to an answer in this question.


Solution

  • I didn't find a suggestion on how much RAM I actually should allocate to the JVM.

    The JVM has a default setting of 1/4 of main memory. If you have 4 GB it will default to 1 GB.

    Note: this is a pretty small system and you get get some embedded devices and phones which this much memory.

    If you can afford to buy a little more memory it will make your life easier.

    I nearly only use Java Applications on it. With how much RAM should I start the JVM?

    Unless you have a reason to change a command line parameter I would leave it as it is.

    Note: you OS will need some memory, perhaps 1 GB and you want to leave 1 GB free for caching etc, so you could increase the heap size to 2 GB, but only if you needed to.

    What if I run 4 programs in parallel? Can I still allocate 2GB for every of that program?

    Yes, but it's a very bad idea. You application will start swapping and your computer can become unusable. I would try to stay under 2 GB total for this machine.

    We have a business application here that often reaches to the maximum allocated Ram, which makes it lag a lot if a user has too many "tabs" open.

    In that case, you should make sure you have the right tool for the job which means making sure your system has enough memory. 4 GB of memory costs $18. If you had a hobby PC with 4 GB, I would say, get more memory. Three years ago, my 8 year old son when he turned 8 I gave him a PC with 8 GB of memory because it's didn't make sense to buy less. I would just get 16 GB or 32 GB minimum. Then its worth spending some time tuning it, maybe.