3

Java is consistently listed as using 700MB of real memory. That is a nice chunk of change on my 4GB iMac. I don't even know that I am running a Java Application, ever.

Any ideas?

3 Answers 3

5

This is due to the nature of garbage collection technology used in Java. Freeing memory in such systems is delayed until some threshold reached, or out of memory happens, or some time passes. It is probably not using all those 700MB all the time (may as well be just 50 MB), but Activity Monitor has no way to look inside Java virtual machine and tell how much is actually used.

Normally, if there are no bugs or leaks (yes GC systems may leak too), Java should give up unused memory whenever your system runs out of it, so there is no need to worry right now. Said that, if you don't need the program, it won't hurt uninstalling whatever is starting it up.

3
  • What you have said can be true or not. I am a JAVA developer and have did some tests, if I limit a spring WEB MVC application to 32M of heap and 256k of thread stack the JAVA process even consumes 250MB, so I run this program inside a docker with limitation of 60MB then the JVM run so slow(missing memory) I've tested with others limits, conclusion: the JVM in this case needs at least 200MB then JAVA really use so much memory
    – deFreitas
    Commented Jun 8, 2016 at 3:20
  • @deFreitas when you size the JVM you have to take into consideration the stack size, the number of threads (they each a stack), the memory used to hold the class structures, and the heap. You can get the JVM down to about 128 MB. AWS Lambdas do that all the time. Add all of these up to see how much you need.
    – Virmundi
    Commented Jan 17, 2019 at 15:10
  • @Virmundi graalvm came to solve memory utilization issue among others
    – deFreitas
    Commented Jan 17, 2019 at 15:29
4

Open up activity monitor, click on the Java process and press Command-I.

From there you might be able to figure out where the process comes from 2 ways

1) Look at open files and ports The open files should give a clue where the process is from or at least what it's reading + writing to.

2) Parent Process You can click on this to open info about the parent process and trace up the parent chain to see what launched the process. If it's launchd, you might be able to look at your launchd config to see where there's a java call in there.

0
2

The archaic explanation:

Java applications require a virtual machine to run because they cannot be are usually not compiled directly into machine language (native code) for many processors, instead Java is usually complied into bytecode. Java is also a very high-level Object-Oriented programming language (OOP) which means that while the application code itself is much easier to maintain, the objects that are instantiated will use that much more memory.

The more modern explanation:

However, many do argue that the problem is usually more so because of the Java program's data structures and architecture, rather than the bytecode. And I tend to agree with that.

There are a number of other reasons why Java apps are using so much system resources (like RAM). For example, most modern applications use the UTF-8 charset, which requires more memory per character, for strings (usually text) as it can support so many other languages' symbols. And since so many applications target a huge international market, they're sorta obligated to use it.

That said, Java arguably remains the most popular programming language at the moment. Many applications that your computer runs are written in Java. That is why.

1
  • Running on a virtual machine doesn't have to mean programs executed by it will use way more memory. The reason is most likely either it is running a program with a memory leak, which can happen if references to objects are saved somewhere but never purged of unused objects (such as in a `HashSet``) for example. Part of the reason is that garbage collection is quite complex. It mainly only runs when it has to like if the memory used is close to a max. Another reason might relate to the footprint of various classes in use although I'm not positive about that possible reason.
    – user904963
    Commented Feb 6, 2022 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .