Github user ctubbsii commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/292#discussion_r132823444
  
    --- Diff: 
core/src/main/java/org/apache/accumulo/core/client/impl/Table.java ---
    @@ -16,24 +16,59 @@
      */
     package org.apache.accumulo.core.client.impl;
     
    +import java.lang.ref.WeakReference;
    +import java.util.WeakHashMap;
    +
     import org.apache.accumulo.core.client.Instance;
     
     public class Table {
     
       /**
        * Object representing an internal table ID. This class was created to 
help with type safety. For help obtaining the value of a table ID from 
Zookeeper, see
        * {@link Tables#getTableId(Instance, String)}
    +   *
    +   * Uses an internal WeakHashMap and private constructor for storing a 
WeakReference of every Table.ID. Therefore, a Table.ID can't be instantiated 
outside
    +   * this class and is accessed by calling Table.ID.{@link #of(String)}.
        */
       public static class ID extends AbstractId {
         private static final long serialVersionUID = 7399913185860577809L;
    +    static final WeakHashMap<String,WeakReference<Table.ID>> tableIds = 
new WeakHashMap<>();
    --- End diff --
    
    It occurs to me that because of Java string interning, using a String as a 
key may mean that entries are kept around longer than necessary. The 
`WeakReference<Table.ID>` will still remove unused `Table.ID` objects and it 
will dedupe when it does exist, but the map entry might stick around 
unnecessarily because the String still has a strong reference because it's used 
in more places than just the Table.ID. This could be avoided by always 
constructing a new String and using that as the canonical parameter and the map 
key... but not sure it's worth it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to