dataset alignments have a reference count which must be zero before they are finalized.
authorjprocter <Jim Procter>
Fri, 24 Aug 2007 15:38:29 +0000 (15:38 +0000)
committerjprocter <Jim Procter>
Fri, 24 Aug 2007 15:38:29 +0000 (15:38 +0000)
src/jalview/datamodel/Alignment.java

index c474142..ba65fd7 100755 (executable)
@@ -190,7 +190,7 @@ public class Alignment
   public void finalize()
   {
     if(getDataset()!=null)
-      getDataset().finalize();
+      getDataset().removeAlignmentRef();
 
     dataset = null;
     sequences = null;
@@ -199,6 +199,16 @@ public class Alignment
     hiddenSequences = null;
   }
 
+  /**
+   * decrement the alignmentRefs counter by one and call finalize if it goes to zero.
+   */
+  private void removeAlignmentRef()
+  {
+    if (--alignmentRefs==0)
+    {
+      finalize();
+    }
+  }
 
   /**
    * DOCUMENT ME!
@@ -638,6 +648,18 @@ public class Alignment
     {
       dataset = data;
     }
+    dataset.addAlignmentRef();
+  }
+  /**
+   * reference count for number of alignments referencing this one.
+   */
+  int alignmentRefs=0;
+  /**
+   * increase reference count to this alignment.
+   */
+  private void addAlignmentRef()
+  {
+    alignmentRefs++;
   }
 
   public Alignment getDataset()