void () { // need to be physical file VirtualFile vf = VfsTestUtil.createFile(getSourceRoot(), "x.txt", "blah"); PsiFile psiFile = Objects.requireNonNull(getPsiManager().findFile(vf)); document = documentManager.getDocument(psiFile); int docHash0 = System.identityHashCode(document); RangeMarker[] oldmarker = {createMarker(psiFile, 1, 3)}; gcDocument(); // 1st resurrection RangeMarker[] marker = {createMarker(psiFile, 1, 3)}; RangeMarker[] persistentMarker = {document.createRangeMarker(1, 3, true)}; assertTrue(marker[0].isValid()); assertEquals("la", marker[0].getTextRange().substring(document.getText())); assertTrue(persistentMarker[0].isValid()); assertEquals("la", persistentMarker[0].getTextRange().substring(document.getText())); int docHash1 = System.identityHashCode(document); assertNotSame(docHash0, docHash1); assertTrue(oldmarker[0].isValid()); gcDocument(); // 2nd resurrection document = Objects.requireNonNull(PsiDocumentManager.getInstance(getProject()).getDocument(psiFile)); int docHash2 = System.identityHashCode(document); assertNotSame(docHash0, docHash1); assertNotSame(docHash0, docHash2); Set<RangeMarker> collectedMarkers = new HashSet<>(); ((DocumentEx)document).processRangeMarkers(new CommonProcessors.CollectProcessor<>(collectedMarkers)); assertSameElements("", collectedMarkers, Arrays.asList(marker[0], persistentMarker[0], oldmarker[0])); collectedMarkers.clear(); assertTrue(oldmarker[0].isValid()); WriteCommandAction.runWriteCommandAction(getProject(), ()->document.insertString(2,"000")); assertTrue(marker[0].isValid()); assertEquals("l000a", marker[0].getTextRange().substring(document.getText())); assertTrue(persistentMarker[0].isValid()); assertEquals("l000a", persistentMarker[0].getTextRange().substring(document.getText())); assertTrue(oldmarker[0].isValid()); oldmarker[0] = null; gcDocument(); checkRMTreesAreGCedWhenNoReachableRangeMarkersLeft(vf, marker, persistentMarker); }