Reputation: 292
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).
we running app using docker image
Upvotes: 2
Views: 3940
Reputation: 719386
There are two potential issues here.
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.
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:
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.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