Link Details

Link 94776 thumbnail
User 160967 avatar

By alarmnummer
via java.dzone.com
Published: Jul 14 2008 / 17:20

This blogs presents a problem (and solution!) where it is required to do some manual after an object is garbage collected. A WeakHashMap was not a good solution because it isn't threadsafe (or scalable) and because the key/value should only be removed when some other object is garbage collected (unlike the WeakHashMap where the key/value is removed when the value is garbage collected).
  • 10
  • 0
  • 780
  • 226

Comments

Add your comment
User 160967 avatar

alarmnummer replied ago:

0 votes Vote down Vote up Reply

With a WeakHashMap the key/value is removed, when the key is unreachable, not the value. My mistake.

But that is exactly the problem I have. I have a throw away key (that is composed of other keys) and I don't want entries to be removed when the key gets garbage collected but only when one of the parts of the key gets garbage collected.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (10)



Voters Against This Link (0)