Interview topics for - how to troubleshoot memory leaks

Java's garbage collection mechanism to facilitate the procedures apes, we may not need to explicitly release resources. But it is not like to sit back and relax, OOM like to hide in dark secluded (hua) Spirit (nong), threatening the poor, the weak and beautiful program ape.

In general, a healthy program, it should not appear in the OOM. Memory objects from birth to death, in order. However, due to some human errors, some objects will often escape sanctions GC, GC jumped outside, not in the trash. This time, a memory leak occurs.

Memory leaks, refer to the application program runs out of memory and this memory (objects no longer needed), does not free the memory space has been filed. Few accidental memory leaks, though not very good, but not a big problem, we will not have to pull Soso pull of memory that point. But if it is a memory leak constantly, until the new object does not have enough space to generate, it will lead to OOM.

When possible memory leak

OOM throw an exception

When the program throws OutOfMemoryError, if you think you are not too stingy, given the program enough space, you can suspect a memory leak

Memory continues to rise

A health program should have a smooth metabolism, memory usage should be maintained at a certain range. But if memory continues to soar, even reach a dangerous value, it can be suspected memory leak.

View GC case

First to get pid application, you can use the jps java command or ps -ef | grep application name Keywords

You can see Eden (E) continued to make objects, and full after years old (O) increases, continue to make the object after E area vacated. (Multi-program execution time, or made subject to mention speed quickly, eventually throws OOM)

View live objects

According to an abnormal growth of live objects, which places parser uses this object can be roughly inferred possible memory leaks.

Guess you like

Origin blog.51cto.com/14230003/2423239