JAL-2216 finalize() refactored so not called programmatically
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 22 Sep 2016 13:33:15 +0000 (14:33 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 22 Sep 2016 13:33:15 +0000 (14:33 +0100)
src/jalview/datamodel/Alignment.java

index 2f64759..35ee8c4 100755 (executable)
@@ -290,13 +290,23 @@ public class Alignment implements AlignmentI
   }
 
   @Override
-  public void finalize()
+  public void finalize() throws Throwable
   {
     if (getDataset() != null)
     {
       getDataset().removeAlignmentRef();
     }
 
+    nullReferences();
+    super.finalize();
+  }
+
+  /**
+   * Defensively nulls out references in case this object is not garbage
+   * collected
+   */
+  void nullReferences()
+  {
     dataset = null;
     sequences = null;
     groups = null;
@@ -305,14 +315,16 @@ public class Alignment implements AlignmentI
   }
 
   /**
-   * decrement the alignmentRefs counter by one and call finalize if it goes to
-   * zero.
+   * decrement the alignmentRefs counter by one and null references if it goes
+   * to zero.
+   * 
+   * @throws Throwable
    */
-  private void removeAlignmentRef()
+  private void removeAlignmentRef() throws Throwable
   {
     if (--alignmentRefs == 0)
     {
-      finalize();
+      nullReferences();
     }
   }