Top Java memory problems

This topic explains frequently occurring memory issues, such as memory leaks, high memory usage, class loader problems, and GC configuration.

Memory leaks

The most common memory leak issue is growing memory leaks, or the constant rise of leaked objects. These leaks can be easily tracked down through trending or histogram dumps.

In comparison, single object leaks are less talked about. As long as there is enough memory, single memory leaks seldom pose a significant problem. However, from time to time, single object leaks occupy a considerable amount of memory and pose a problem. The good news is that single big leaks can be easily identified by heap analyzer tools.

The following are some of the causes of memory leaks:

High memory usage

Too much memory usage is an increasingly frequent and critical problem in today’s enterprise applications. Although the average server often has 10, 20, or more GB of memory, a high degree of parallelism and a lack of awareness lead to memory shortages. Another issue is that while it is possible to use multiple gigabytes of memory in today’s JVMs, the side effects a very long GC pauses. In some cases, increasing the memory can be a workaround to memory leaks or badly written software. However, more often than not, this makes things worse in the long run and not better. The following are the most common causes of high memory usage:

In modern enterprise applications, the memory requirements for loaded classes can quickly amount to several hundred MB and contribute to memory problems. In the Hotspot JVM, classes are located in the permanent generation or PermGen. It represents a separate memory area, and its size must be configured separately. If this area is full, no more classes can be loaded, and an out-of-memory occurs in the PermGen. The other JVMs do not have a permanent generation, but that does not solve the problem. Class loader problems are some of the most difficult problems to detect. Most developers never have to deal with this topic and tool support is also poorest in this area. The following are some such problems: