From 37e1fa33b20cd2fb68cb7f72c15784897cb8a6b1 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 22 Sep 2016 14:19:44 +0100 Subject: [PATCH 1/1] JAL-2216 new dispose() method to null references --- src/jalview/api/AlignViewportI.java | 5 ++++ src/jalview/gui/AlignViewport.java | 3 ++- src/jalview/viewmodel/AlignmentViewport.java | 35 +++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 4 deletions(-) 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; -- 1.7.10.2