[Biojava-l] ChangeSupport.java

Phillip Lord p.lord@russet.org.uk
05 Mar 2002 13:37:48 +0000


>>>>> "Thomas" == Thomas Down <td2@sanger.ac.uk> writes:

  Thomas>   - It keeps hard references to the listeners, rather than
  Thomas> using the java.lang.ref package to maintain weak references.
  Thomas> It becomes very easy to listen to a `global' object (for
  Thomas> instance, the DNA Alphabet), and effectively make your
  Thomas> object un-garbage-collectable.

        I did this once (not with biojava, but my own dodgy
code!). 200Mb object graph hanging off one reference. Took me two days
to track down.

        Perhaps the solution to this is at the level of the global 
object. If the global objects are mutable in any way, they probably
should not be global objects. If they are immutable, then they can
safely discard any listeners added to them, since they are not going
to change, and therefore the listeners will never need to be
signalled, which in turn prevents the GC problem. 

        Of course the Weak References prevent problems that can 
occur when you write a singleton immutable class on a friday afternoon,
and forget to override the addListener() method to do nothing, which
was my mistake, so take this with a pinch of salt.

        Cheers

        Phil