Is there a memory leak in Java?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.