Expired referenced memory leaks caused by weakHashMap avoid

The origin of the problem

Array-based collections realized on exit element, does not take a reference point to a null pointer, outdated reference object exists would not have been recovered.

Measure

Wherein when the key 1.WeakHashMap when no longer referenced externally, will be recovered. ThreadLocal uses WeakHashMap

2.LinkedHashMap of removeEldestEntry method:

By covering this method, addition of certain conditions, the condition returns true. When put into the new value method returns true, then remove the oldest map key.

3.java.lang.ref:

Strong Reference

Soft Reference

Weak Reference

Phantom Reference

4. Analysis by Heap Profiler

Guess you like

Origin www.cnblogs.com/lccsblog/p/10992454.html