From: gmungoc Date: Thu, 22 Sep 2016 13:33:15 +0000 (+0100) Subject: JAL-2216 finalize() refactored so not called programmatically X-Git-Tag: Release_2_10_0~39^2^2~7 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b5f7b522ab8055c94a5266fb338a1abaaa58a159;p=jalview.git JAL-2216 finalize() refactored so not called programmatically --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 2f64759..35ee8c4 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -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(); } }