call to release any explicit event handler references and fix for occasional arrayInd...
[jalview.git] / src / jalview / structure / StructureSelectionManager.java
index 0e4ec2f..492907b 100644 (file)
@@ -215,7 +215,7 @@ public class StructureSelectionManager
 
       // allocate enough slots to store the mapping from positions in
       // sequence[s] to the associated chain
-      int[][] mapping = new int[maxChain.sequence.getEnd() + 2][2];
+      int[][] mapping = new int[sequence[s].findPosition(sequence[s].getLength()) + 2][2];
       int resNum = -10000;
       int index = 0;
 
@@ -259,6 +259,17 @@ public class StructureSelectionManager
   public void removeStructureViewerListener(Object svl, String[] pdbfiles)
   {
     listeners.removeElement(svl);
+    if (svl instanceof SequenceListener)
+    {
+      for (int i=0;i<listeners.size();i++)
+      {
+        if (listeners.elementAt(i) instanceof StructureListener)
+        {
+          ((StructureListener)listeners.elementAt(i)).releaseReferences(svl);
+        }
+      }
+    }
+      
     if (pdbfiles == null)
     {
       return;