Balzanka / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Interners should allow more inspection #1345

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Strong internerners are faster and more memory efficient than weak interners, 
however they introduce the potential to create memory leaks if you intern 
objects that turn out to be unnecessary - something you often cannot decide 
until after you've interned.

Take for example the case where you're using IdentityHashMaps, and intern the 
keys in order to ensure your objects are identical.  In order to do a 
map.containsKey() check you need to intern the object, but if map.contiansKey() 
returns false, you might as well have not interned the object in the first 
place, and making many of these calls potentially adds many useless objects to 
the intern store.  As is, you're currently forced to use a weak interner 
instead, which seems silly seeing as most interners are simply wrappers around 
ConcurrentHashMaps and could easily provide contains-check functionality.

As such, I propose that an additional interface, InspectableInterner extends 
Interner, be created which enables runtime inspection of the given Interner, 
with methods like isInterned() and size().  Further, the Interner objects 
returned by the Interners class should now be instances of InspectableInterner. 
 This will maintain backwards-compatibility while easily enabling this 
functionality for users who want it.

Happy to prepare such a patch if desired.

Original issue reported on code.google.com by dimo414 on 18 Mar 2013 at 6:08

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 8 Apr 2013 at 7:00

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:18

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08