void () { // need to be physical file VirtualFile vf = VfsTestUtil.createFile(getSourceRoot(), "x.txt", "blah"); PsiFile psiFile = Objects.requireNonNull(getPsiManager().findFile(vf)); RangeMarker[] marker = {createMarker(psiFile, 0, 4)}; RangeMarker[] persistentMarker = {document.createRangeMarker(0, 4, true)}; int docHash0 = System.identityHashCode(document); gcDocument(); assertTrue(marker[0].isValid()); assertTrue(persistentMarker[0].isValid()); document = Objects.requireNonNull(PsiDocumentManager.getInstance(getProject()).getDocument(psiFile)); int docHash1 = System.identityHashCode(document); assertNotSame(docHash0, docHash1); WriteCommandAction.runWriteCommandAction(getProject(), ()->document.insertString(2,"000")); assertTrue(marker[0].isValid()); assertEquals("bl000ah", marker[0].getTextRange().substring(document.getText())); assertTrue(persistentMarker[0].isValid()); assertEquals("bl000ah", persistentMarker[0].getTextRange().substring(document.getText())); gcDocument(); checkRMTreesAreGCedWhenNoReachableRangeMarkersLeft(vf, marker, persistentMarker); }