//Discard the strong reference to the key name = null; while (true) { System.gc(); /** * Verify Full GC with the -verbose:gc option Since there is no strong reference to the key, it is assumed that the entry has been removed from the WeakHashMap */ System.out.println(cache.size()); } }

Now when the testMethod() is run what do you expect the output to be? Since the strong reference to key is discarded, we assume that the entry from the map would be removed, and map would be empty after a full GC.But that does not happen though.

Let us see what was the put operation on the WeakHashMap.

cache.put(name, new ComplexDO("1", name));

Here the value ComplexDO was holding the key name. This would mean that the value always strongly refers to the key, and hence the key would never be garbage collected. The entry would always remain the map.

This is what WeakHashMap API says - "The value objects in a WeakHashMap are held by ordinary strong references. Thus care should be taken to ensure that value objects do not strongly refer to their own keys, either directly or indirectly, since that will prevent the keys from being discarded."

It was amazing to receive many good info in this survey. To improve the business it's suggested to use software outsourcing development to appear on IT markets. Software development allows to automate business processes and gain more profits.

Only few shipper loan banks don't require the dealer to change their charge card processors organization. Most time this won't be an issue at all since the rates will be coordinated. Online Payday Loan corona