From: gmungoc Date: Thu, 22 Sep 2016 13:19:44 +0000 (+0100) Subject: JAL-2216 new dispose() method to null references X-Git-Tag: Release_2_10_0~39^2^2~8 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=37e1fa33b20cd2fb68cb7f72c15784897cb8a6b1;p=jalview.git JAL-2216 new dispose() method to null references --- diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index c08527c..0840520 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -122,6 +122,11 @@ public interface AlignViewportI extends ViewStyleI boolean isClosed(); /** + * Dispose of all references or resources held by the viewport + */ + void dispose(); + + /** * get the associated calculation thread manager for the view * * @return diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 62e05d0..f755b25 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -419,10 +419,11 @@ public class AlignViewport extends AlignmentViewport implements * @param align * DOCUMENT ME! */ + @Override public void setAlignment(AlignmentI align) { replaceMappings(align); - this.alignment = align; + super.setAlignment(align); } /** diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index a746e1f..cb43d90 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -58,6 +58,7 @@ import jalview.workers.ConsensusThread; import jalview.workers.StrucConsensusThread; import java.awt.Color; +import java.beans.PropertyChangeSupport; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.BitSet; @@ -914,6 +915,35 @@ public abstract class AlignmentViewport implements AlignViewportI, return false; } + public void setAlignment(AlignmentI align) + { + this.alignment = align; + } + + /** + * Clean up references when this viewport is closed + */ + @Override + public void dispose() + { + /* + * defensively null out references to large objects in case + * this object is not garbage collected (as if!) + */ + consensus = null; + complementConsensus = null; + strucConsensus = null; + conservation = null; + quality = null; + groupConsensus = null; + groupConservation = null; + hconsensus = null; + hcomplementConsensus = null; + // TODO removed listeners from changeSupport? + changeSupport = null; + setAlignment(null); + } + @Override public boolean isClosed() { @@ -1241,10 +1271,9 @@ public abstract class AlignmentViewport implements AlignViewportI, return ignoreGapsInConsensusCalculation; } - // / property change stuff - + // property change stuff // JBPNote Prolly only need this in the applet version. - private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport( + private PropertyChangeSupport changeSupport = new PropertyChangeSupport( this); protected boolean showConservation = true;