[Biojava-dev] memory leak

Michael Heuer heuermh at acm.org
Fri Jan 28 14:25:17 EST 2005


On Fri, 28 Jan 2005 mark.schreiber at group.novartis.com wrote:

> Looking at this further.
>
> The parent SymbolList adds ChangeListeners to all it's children that are
> created during subList() or subStr() operations. The children of these
> subXXX operations are views on the parent. Any Edit operations performed
> on them are notified to the parent and applied to the parent (who knew?
> how cool!). So that answers the question about what they are for and also
> why they are not cleaned up.
>
> Following your clue about the reapGarbageListeners() method your correct
> that it is never called. The only place it can be called is from
> ChangeSupport.firePreChangeEvent or ChangeSupport.firePostChangeEvent.
> Because nothing we are doing in the loop is actually causing anything to
> change there is no chance for reapListeners() to be called.
>
> To test this out I changed the loop to:
>
>     while(true){
>       SymbolList sl2 = sl.subList(1,12);
>       Edit e = new Edit(4, DNATools.getDNA(), DNATools.g());
>       sl2.edit(e);
>     }
>
> This forces a changeEvent and results in garbageCollection of the
> WeakReferences and bingo, no more memory leak.
>
> So, there needs to be some mechanism by which reapGarbageListeners() can
> be called without the need for a changeEvent. I'm thinking that the
> finalize() method of SimpleSymbolList might call it but this is not
> currently possible as the reapListeners() method is protected and in a
> different package. Maybe the finalize() method could throw a dummy
> changeEvent as a bit of a hack and to signal to the world it is dying.

How about being called from the synchronized blocks in add and
removeChangeListener?

   michael



More information about the biojava-dev mailing list