JAL-2379 null references to PCA model when panel is closed
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 12 Jan 2017 16:44:09 +0000 (16:44 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 12 Jan 2017 16:44:09 +0000 (16:44 +0000)
src/jalview/gui/PCAPanel.java

index 4f5a018..aa01bf5 100644 (file)
@@ -46,8 +46,9 @@ import javax.swing.ButtonGroup;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JColorChooser;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
 import javax.swing.JRadioButtonMenuItem;
+import javax.swing.event.InternalFrameAdapter;
+import javax.swing.event.InternalFrameEvent;
 
 /**
  * DOCUMENT ME!
@@ -81,6 +82,7 @@ public class PCAPanel extends GPCAPanel implements Runnable,
    */
   public PCAPanel(AlignmentPanel ap)
   {
+    super();
     this.av = ap.av;
     this.ap = ap;
 
@@ -121,6 +123,16 @@ public class PCAPanel extends GPCAPanel implements Runnable,
 
       return;
     }
+
+    addInternalFrameListener(new InternalFrameAdapter()
+    {
+      @Override
+      public void internalFrameClosed(InternalFrameEvent e)
+      {
+        close_actionPerformed();
+      }
+    });
+
     pcaModel = new PCAModel(seqstrings, seqs, nucleotide);
     PaintRefresher.Register(this, av.getSequenceSetId());
 
@@ -130,6 +142,15 @@ public class PCAPanel extends GPCAPanel implements Runnable,
     worker.start();
   }
 
+  /**
+   * Ensure references to potentially very large objects (the PCA matrices) are
+   * nulled when the frame is closed
+   */
+  protected void close_actionPerformed()
+  {
+    pcaModel = null;
+  }
+
   @Override
   protected void scoreMatrix_menuSelected()
   {