void () { FileDocumentManager.getInstance().saveAllDocuments(); assertNotNull(document); Reference<Document> ref = new WeakReference<>(document); psiFile = null; fileNode = null; document = null; TestTimeOut t = TestTimeOut.setTimeout(60, TimeUnit.SECONDS); while (ref.get() != null && !t.isTimedOut()) { GCUtil.tryGcSoftlyReachableObjects(); UIUtil.dispatchAllInvocationEvents(); } Document d = ref.get(); if (t.isTimedOut() && d != null) { int hashCode = System.identityHashCode(d); Class<?> aClass = d.getClass(); d = null; LeakHunter.checkLeak(LeakHunter.allRoots(), aClass, leakedDoc -> System.identityHashCode(leakedDoc) == hashCode); fail("Unable to gc the document"); } }