Merge branch 'bug/JAL-2864nullOverviewCanvas' into develop
authorJim Procter <jprocter@issues.jalview.org>
Mon, 17 Dec 2018 17:30:44 +0000 (17:30 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 17 Dec 2018 17:30:44 +0000 (17:30 +0000)
src/jalview/appletgui/OverviewCanvas.java
src/jalview/appletgui/OverviewPanel.java
src/jalview/gui/OverviewCanvas.java
test/jalview/gui/FreeUpMemoryTest.java

index e99c021..07f5919 100644 (file)
@@ -162,4 +162,12 @@ public class OverviewCanvas extends Component
     }
   }
 
+  /**
+   * Nulls references to protect against potential memory leaks
+   */
+  void dispose()
+  {
+    od = null;
+  }
+
 }
index 3bbbe95..5081509 100755 (executable)
@@ -334,6 +334,10 @@ public class OverviewPanel extends Panel implements Runnable,
     } finally
     {
       av = null;
+      if (oviewCanvas != null)
+      {
+        oviewCanvas.dispose();
+      }
       oviewCanvas = null;
       ap = null;
       od = null;
index cc361a5..89088b8 100644 (file)
@@ -257,6 +257,7 @@ public class OverviewCanvas extends JComponent
   public void dispose()
   {
     dispose = true;
+    od = null;
     synchronized (this)
     {
       restart = true;
index e93bfac..9b21274 100644 (file)
@@ -1,6 +1,7 @@
 package jalview.gui;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertTrue;
 
 import jalview.analysis.AlignmentGenerator;
@@ -11,6 +12,7 @@ import jalview.datamodel.SequenceGroup;
 import jalview.io.DataSourceType;
 import jalview.io.FileLoader;
 
+import java.awt.event.MouseEvent;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
@@ -18,6 +20,8 @@ import java.io.PrintStream;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import junit.extensions.PA;
+
 public class FreeUpMemoryTest
 {
   private static final int ONE_MB = 1000 * 1000;
@@ -30,16 +34,12 @@ public class FreeUpMemoryTest
   {
     Jalview.main(new String[] { "-nonews", "-props",
         "test/jalview/testProps.jvprops" });
-    Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS",
-            Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_QUALITY",
-            Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_CONSERVATION",
-            Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_OCCUPANCY",
-            Boolean.TRUE.toString());
-    Cache.applicationProperties.setProperty("SHOW_IDENTITY",
-            Boolean.TRUE.toString());
+    String True = Boolean.TRUE.toString();
+    Cache.applicationProperties.setProperty("SHOW_ANNOTATIONS", True);
+    Cache.applicationProperties.setProperty("SHOW_QUALITY", True);
+    Cache.applicationProperties.setProperty("SHOW_CONSERVATION", True);
+    Cache.applicationProperties.setProperty("SHOW_OCCUPANCY", True);
+    Cache.applicationProperties.setProperty("SHOW_IDENTITY", True);
   }
 
   /**
@@ -84,18 +84,19 @@ public class FreeUpMemoryTest
   protected void checkUsedMemory(long expectedMax)
   {
     /*
-     * request garbage collection and wait briefly for it to run;
+     * request garbage collection and wait for it to run;
      * NB there is no guarantee when, or whether, it will do so
+     * wait time depends on JRE/processor, generous allowance here  
      */
     System.gc();
-    waitFor(100);
+    waitFor(1500);
 
     /*
      * a second gc() call should not be necessary - but it is!
      * the test passes with it, and fails without it
      */
     System.gc();
-    waitFor(100);
+    waitFor(1500);
 
     /*
      * check used memory is 'reasonably low'
@@ -142,6 +143,20 @@ public class FreeUpMemoryTest
     }
 
     /*
+     * open an Overview window
+     */
+    af.overviewMenuItem_actionPerformed(null);
+    assertNotNull(af.alignPanel.overviewPanel);
+
+    /*
+     * exercise the pop-up menu in the Overview Panel (JAL-2864)
+     */
+    Object[] args = new Object[] {
+        new MouseEvent(af, 0, 0, 0, 0, 0, 1, true) };
+    PA.invokeMethod(af.alignPanel.overviewPanel,
+            "showPopupMenu(java.awt.event.MouseEvent)", args);
+
+    /*
      * set a selection group - potential memory leak if it retains
      * a reference to the alignment
      */