Avoiding Memory Leaks
In the previous chapter, we examined how to configure and monitor memory management in the JVM. This involved knowledge of the metrics relevant to the tuning of the JVM. We discussed how to obtain these metrics and, consequently, how to tune the JVM. We also examined how to use profiling to obtain insights into the effects of tuning.
This chapter focuses on memory leaks. We will examine memory leaks under the following headings:
- Understanding memory leaks
- Spotting memory leaks
- Avoiding memory leaks
Let us start with understanding memory leaks. After that, we will learn how to spot them in our code and see how to avoid and solve them.