saij9999
saij9999

Reputation: 292

Tenured Generation Garbage Collection is Not clearing

I have a java spring boot project. When the code related to multi-threading (Executor service)is executed memory is getting filled. GC is not clearing this memory. After reading GC docs, came to know that the tenured memory is not getting cleared. By monitoring the JVM by Java Profiler, I notice that this Tenured Generation never get cleared(until full, for my case).

  1. how can I make gc clear the tenured space?

we running app using docker image

Upvotes: 2

Views: 3940

Answers (1)

Stephen C
Stephen C

Reputation: 719386

There are two potential issues here.

  1. The garbage collector, can only release objects that are unreachable. So if the tenured objects are still reachable, they won't ever be released. This is a memory leak scenario.

  2. The JVM could be not running the old / tenured space collection because it doesn't need to. The JVM will typically only run the old space collector when it thinks it is necessary / economical to do. This is actually a good thing, because most of the easily (cheaply) collectable garbage is normally in the new space.


After reading gc docs, came to know that the tenured memory is not getting cleared.

That's probably a misreading of the documentation. The GC will collect objects in tenured space. It should happen before you start getting OOMEs.


How can I make the GC clear the tenured space?

You can call System.gc() ... which gives the JVM a hint that it would be a good thing to run the GC now. However:

  • It is only a hint. The JVM may ignore it.
  • It may or may not run an old space collection.
  • It won't "clear" the old generation. It won't necessarily even release all of the unreachable objects.
  • It is generally inefficient to call System.gc(). The JVM typically has a better idea of the most efficient time to run the GC, and which kind of GC to run.
  • Running the GC is probably not actually going to release memory for the rest of the system to use.

In short, it is probably a BAD IDEA to call System.gc(). In most cases, it doesn't achieve anything.

It certainly help if your real problem is a memory leak. If you are getting OOME's, it won't help.

Upvotes: 1

Related Questions