[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: Composite Map key and weak reference

alesj do-not-reply at jboss.com
Thu May 22 06:12:38 EDT 2008


"bstansberry at jboss.com" wrote : 
  | 
  |   | public class Key
  |   | {
  |   |    private static final ReferenceQueue refQueue = new ReferenceQueue();
  |   |    
  |   |    private final KeyRef keyRef;
  |   |    private final WeakReference<Annotation>[] annotations;
  |   |    
  |   |    public Key(Class clazz, Annotation[] annotations)
  |   |    {
  |   |       this.keyRef = new KeyRef(this, clazz, refQueue);
  |   |       this.annotations = new WeakReference[annotations.length];
  |   |       for (int j = 0; j < annotations.length; j++)
  |   |       {
  |   |          this.annotations[j]= new WeakReference<Annotation>(annotations[j]);
  |   |       }
  |   |    }
  |   | 
Do I really need these annotations to be wrapped in weak refs?
Wouldn't they get immediately gced?

Or if I just leave them strong, my whole Key instance will be gc candidate the moment I nullify it in here

  |     while ((ref = refQueue.poll()) != null)
  |       {
  |          ((KeyRef) ref).key = null;
  |       }      
  | 
since nothing else now has a strongly ref on it.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4152608#4152608

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4152608



More information about the jboss-dev-forums mailing list