code: private void removeDoc(String docID) {
      int rmNum = -1;
      int docNum = -1;
      for (int i = 0; i < documents.size(); i++) {
        XComponent xComponent = documents.get(i).getXComponent();
        if (xComponent != null && xComponent.equals(goneContext)) { //  disposed document found
          rmNum = i;
          break;
        }
      }
      if(rmNum < 0) {
        MessageHandler.printToLogFile("Error: Disposed document not found");
        goneContext = null;
      }
      for (int i = 0; i < documents.size(); i++) {
        if (documents.get(i).getDocID().equals(docID)) {  //  document exist
          docNum = i;
          break;
        }
      }
      if(rmNum >= 0 && docNum != rmNum ) {  // don't delete a closed document before the last check is done
        documents.remove(rmNum);
        goneContext = null;
        if (debugMode) {
          MessageHandler.printToLogFile("Document " + rmNum + " deleted");
        }
      }
    }
docs: Delete a document number and all internal space