Java Memory leak scenarios

Source: Internet
Author: User

Override hashcode member variable changed, object in set cannot find

1. Use the Hashcode function of the object to determine the memory location initially, and if there is no storage object at that location, store the object in this

2, if the hash function directly calculated memory address space already has an object exists, will use the object's equals to determine whether the object is equal, if not equal the order to find the next free memory space, if the same object exists, the duplicate object cannot be stored in the set

When an object is stored in the HashSet collection, it is not possible to modify those fields in the object that participate in the hash value calculation, otherwise, the object's modified hash value is different, in which case, Even if the Contains method uses the object's current reference as a parameter to retrieve an object in conjunction with HashSet, it will also return the result of the object not found, which will also result in a memory leak by deleting the current object separately from the collection in the HashSet. The so-called memory leak means that an object is not reused, but it occupies memory space and is not released.

Java Memory leak scenarios

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.