Map of Java garbage collection [original]

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 in the project. Article , When no pointer points to the value, the key will be recycled and it will be used for a cachemap. You need to add a method.

Package Org. OFBiz. Payment. Common;

ImportJava. util. iterator;
ImportJava. 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.