A memory leak is an object or variable that is no longer being used and is always occupied in memory. However, there is a garbage collection mechanism in Java that can automatically purge objects that are no longer in use from memory.
Even so, there is a case of memory leaks in Java:
One: Memory leaks are most likely to occur when long-life-cycle objects hold references to objects of a short life cycle. Although objects of a short life cycle are no longer needed, long life-cycle objects hold their references so that they cannot be recycled. For example, caching the system, loading an object into the cache system, and never using the object, but it has been cached for reference, so it will not be recycled to cause a cache leak.
Check the memory leaks in Java, be sure to complete the execution of each branch of the program to the end, and then see if it has been used, if there is no way to determine that the object belongs to a memory leak.
Second: When an object is stored in the HashSet collection, it is not allowed to modify the properties of the object used to compute the hash value. Otherwise, if the object's modified hash value is not the same as the hash value that was just added to the HashSet collection, if the current object's reference is used as a parameter and the Contains method is used to determine if the object exists, the result of the object cannot be found. This causes the current object to be deleted from HashSet, causing a memory leak
Reference Address: http://www.cnblogs.com/guweiwei/p/6641762.html
Is there a memory leak in Java?