Ask Your Question

Java memory usage

asked 2018-06-30 11:00:20 -0600

Davide Sestili gravatar image

My Java executable uses 12 MB of memory on Windows while on Fedora 28 it uses about 80 MB of memory, why? The processed data is roughly the same and on both Windows and Linux the process ends without errors.

edit retag flag offensive close merge delete


This behavior begins after upgrade to fedora 28.

Davide Sestili gravatar imageDavide Sestili ( 2018-07-01 16:19:33 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2018-06-30 22:57:03 -0600

abadrinath gravatar image

I would refer to villykruse's answer if you want to know how to reduce the size of the memory usage.

I, myself, would not worry about the memory usage of a program unless you're doing some commercial applications or developing something extremely complex that will fill up a standard amount of memory nowadays. RAM is meant to be used by running processes and Linux is very good about not keeping it empty (using cache, etc.). Empty RAM is kind of a waste for the system.

That said, Java doesn't have a great track record with memory management. Take a look at this:

Sometimes, unused objects don't go to the built-in Java garbage collection and ends up sitting on your memory. Memory leaking is a big issue when it's a lot of memory, but honestly, I don't see 80MB vs 12MB really impacting anything.

Hope that helps.

edit flag offensive delete link more


Before upgrading to Fedora 28 the program was run without problems of performace or memory leaks, maybe there are problems with the new kernel or the new JVM.

Davide Sestili gravatar imageDavide Sestili ( 2018-07-17 10:49:40 -0600 )edit

answered 2018-06-30 16:37:36 -0600

villykruse gravatar image

The memory usage depends on the size of the heap you specify. This is defined by the -Xms and -Xmx arguments given to the java command. If too little, java spends too much time with garbage collection. If to high, it may start swapping instead. Both is bad for performance.

See for example How is the default Java heap size determined?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-06-30 11:00:20 -0600

Seen: 89 times

Last updated: Jun 30 '18