Proper referencing
It is undeniable – memory leaks can result in a gradual decrease in resource availability and lead to sluggish systems and potential system crashes. The good news is that there are two major components that offer a solution. One component is the garbage collector that is part of the Java Virtual Machine (JVM). It is highly capable and one of the shining characteristics of the Java language. The second, and more important, component is the developer. As Java developers, we have the power to minimize and even eliminate memory leaks by taking a purposeful approach to memory management in our code.
To support the developer component of the solution to eradicate memory leaks, this section will focus on how to properly reference objects so that they do not lead to memory leaks, how to identify memory leaks, and the strategies to avoid them.
An introduction to references
Perhaps the most important aspect of avoiding memory leaks is to use proper referencing...