Java garbage collection Map

Source: Internet
Author: User
For a long time, map is very popular. In small-scale applications, map is nothing to use. However, a large number of applications require attention in terms of Memory Applications.
A few months ago, map was used when I was working on the project. In an article, I remember that there was a problem with map recycling. After a try, when it was set to null, still cannot be effectively recycled. I found some information and finally weakhashmap. When no Pointer Points to value, the key will be recycled and a cachemap will be used. I need to add another method.

Package org. OFBiz. Payment. Common;

Import java. util. iterator;
Import java. util. weakhashmap;

/**
* @ Author zxub 2006-3-22 10:03:22
*/
Public class cachemap extends weakhashmap
{
Public object getkeybyvalue (object value)
{
Object returnvalue = NULL;
Object key = NULL;
For (iterator iter = This. keyset (). iterator (); ITER. hasnext ();)
{
Key = ITER. Next ();
If (this. Get (key). Equals (value ))
{
Returnvalue = key;
Break;
}
}
Return returnvalue;
}
}

The application here is the opposite of map. After testing, the memory can be effectively released.
 

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.