void () { Key<SmartPointerEx<PsiClass>> key = Key.create("smart pointer test"); Runnable createFileAndPointer = () -> { PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText("a.java", JavaLanguage.INSTANCE, "class Foo {}", true, false); SmartPointerEx<PsiClass> pointer = createPointer(((PsiJavaFile)file).getClasses()[0]); file.getViewProvider().getDocument().putUserData(key, pointer); }; createFileAndPointer.run(); GCUtil.tryGcSoftlyReachableObjects(); SmartPointerTracker.processQueue(); LeakHunter.checkLeak(LeakHunter.allRoots(), Document.class, d -> !(d instanceof FrozenDocument) && d.getUserData(key) != null); }