From 89f6349fbcbaadc2f330c0cc7f567f7f0e60f5c0 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 22 Sep 2016 14:47:11 +0100 Subject: [PATCH] JAL-2216 explicitly null AnnotationPanel and AnnotationRenderer fields when closing AlignmentPanel --- src/jalview/gui/AlignmentPanel.java | 19 +++- src/jalview/gui/AnnotationPanel.java | 26 ++++- src/jalview/renderer/AnnotationRenderer.java | 141 ++++++++++++++------------ 3 files changed, 114 insertions(+), 72 deletions(-) diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 87d5933..424d52f 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -101,6 +101,8 @@ public class AlignmentPanel extends GAlignmentPanel implements */ private boolean dontScrollComplement; + private PropertyChangeListener propertyChangeListener; + /** * Creates a new AlignmentPanel object. * @@ -135,7 +137,7 @@ public class AlignmentPanel extends GAlignmentPanel implements vscroll.addAdjustmentListener(this); final AlignmentPanel ap = this; - av.addPropertyChangeListener(new PropertyChangeListener() + propertyChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) @@ -146,7 +148,8 @@ public class AlignmentPanel extends GAlignmentPanel implements alignmentChanged(); } } - }); + }; + av.addPropertyChangeListener(propertyChangeListener); fontChanged(); adjustAnnotationHeight(); updateLayout(); @@ -1595,8 +1598,18 @@ public class AlignmentPanel extends GAlignmentPanel implements PaintRefresher.RemoveComponent(getSeqPanel().seqCanvas); PaintRefresher.RemoveComponent(getIdPanel().getIdCanvas()); PaintRefresher.RemoveComponent(this); + + /* + * try to ensure references are nulled + */ + if (annotationPanel != null) + { + annotationPanel.dispose(); + } + if (av != null) { + av.removePropertyChangeListener(propertyChangeListener); jalview.structure.StructureSelectionManager ssm = av .getStructureSelectionManager(); ssm.removeStructureViewerListener(getSeqPanel(), null); @@ -1604,7 +1617,7 @@ public class AlignmentPanel extends GAlignmentPanel implements ssm.removeCommandListener(av); ssm.removeStructureViewerListener(getSeqPanel(), null); ssm.removeSelectionListener(getSeqPanel()); - av.setAlignment(null); + av.dispose(); av = null; } else diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 7450555..0b2f6cc 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -123,8 +123,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, boolean mouseDragging = false; - boolean MAC = false; - // for editing cursor int cursorX = 0; @@ -142,9 +140,6 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, */ public AnnotationPanel(AlignmentPanel ap) { - - MAC = jalview.util.Platform.isAMac(); - ToolTipManager.sharedInstance().registerComponent(this); ToolTipManager.sharedInstance().setInitialDelay(0); ToolTipManager.sharedInstance().setDismissDelay(10000); @@ -1139,4 +1134,25 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, return null; } } + + /** + * Try to ensure any references held are nulled + */ + public void dispose() + { + av = null; + ap = null; + image = null; + fadedImage = null; + gg = null; + _mwl = null; + + /* + * I created the renderer so I will dispose of it + */ + if (renderer != null) + { + renderer.dispose(); + } + } } diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index 82f6ffb..e58ba02 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -30,6 +30,7 @@ import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; +import jalview.util.Platform; import java.awt.BasicStroke; import java.awt.Color; @@ -57,6 +58,70 @@ public class AnnotationRenderer */ private final boolean debugRedraw; + private int charWidth, endRes, charHeight; + + private boolean validCharWidth, hasHiddenColumns; + + private FontMetrics fm; + + private final boolean MAC = Platform.isAMac(); + + boolean av_renderHistogram = true, av_renderProfile = true, + av_normaliseProfile = false; + + ColourSchemeI profcolour = null; + + private ColumnSelection columnSelection; + + private Hashtable[] hconsensus; + + private Hashtable[] complementConsensus; + + private Hashtable[] hStrucConsensus; + + private boolean av_ignoreGapsConsensus; + + /** + * attributes set from AwtRenderPanelI + */ + /** + * old image used when data is currently being calculated and cannot be + * rendered + */ + private Image fadedImage; + + /** + * panel being rendered into + */ + private ImageObserver annotationPanel; + + /** + * width of image to render in panel + */ + private int imgWidth; + + /** + * offset to beginning of visible area + */ + private int sOffset; + + /** + * offset to end of visible area + */ + private int visHeight; + + /** + * indicate if the renderer should only render the visible portion of the + * annotation given the current view settings + */ + private boolean useClip = true; + + /** + * master flag indicating if renderer should ever try to clip. not enabled for + * jalview 2.8.1 + */ + private boolean canClip = false; + public AnnotationRenderer() { this(false); @@ -74,6 +139,18 @@ public class AnnotationRenderer this.debugRedraw = debugRedraw; } + /** + * Remove any references and resources when this object is no longer required + */ + public void dispose() + { + hconsensus = null; + complementConsensus = null; + hStrucConsensus = null; + fadedImage = null; + annotationPanel = null; + } + void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX, int x, int y, int iconOffset, int startRes, int column, boolean validRes, boolean validEnd) @@ -134,70 +211,6 @@ public class AnnotationRenderer g.fillRect(x1, y + 4 + iconOffset, x2 - x1, 7); } - private int charWidth, endRes, charHeight; - - private boolean validCharWidth, hasHiddenColumns; - - private FontMetrics fm; - - private final boolean MAC = jalview.util.Platform.isAMac(); - - boolean av_renderHistogram = true, av_renderProfile = true, - av_normaliseProfile = false; - - ColourSchemeI profcolour = null; - - private ColumnSelection columnSelection; - - private Hashtable[] hconsensus; - - private Hashtable[] complementConsensus; - - private Hashtable[] hStrucConsensus; - - private boolean av_ignoreGapsConsensus; - - /** - * attributes set from AwtRenderPanelI - */ - /** - * old image used when data is currently being calculated and cannot be - * rendered - */ - private Image fadedImage; - - /** - * panel being rendered into - */ - private ImageObserver annotationPanel; - - /** - * width of image to render in panel - */ - private int imgWidth; - - /** - * offset to beginning of visible area - */ - private int sOffset; - - /** - * offset to end of visible area - */ - private int visHeight; - - /** - * indicate if the renderer should only render the visible portion of the - * annotation given the current view settings - */ - private boolean useClip = true; - - /** - * master flag indicating if renderer should ever try to clip. not enabled for - * jalview 2.8.1 - */ - private boolean canClip = false; - void drawNotCanonicalAnnot(Graphics g, Color nonCanColor, Annotation[] row_annotations, int lastSSX, int x, int y, int iconOffset, int startRes, int column, boolean validRes, -- 1.7.10.2