[Biojava-l] ChangeSupport.java

Thomas Down td2@sanger.ac.uk
Tue, 5 Mar 2002 13:51:25 +0000


Hi...

Global objects are only one case of something which can
potentially have a lot of other objects listening to them,
albeit an important one.  But yes, you're certainly right
insofar as that if they're really immutable, they don't
need ChangeSupport.

That said, I still think the WeakReference approach is
a rather valuable safety net -- I'd prefer not to throw
it out until we know for sure that it's sucking up a lot
of processor cycles.  I'm quite busy this afternoon though --
anyone else feel like running some benchmarks?  If not, I'll
try to get them done in the next few days.


      Thomas.



On Tue, Mar 05, 2002 at 01:37:48PM +0000, Phillip Lord wrote:
> >>>>> "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.