diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/EditorHistoryManagerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/EditorHistoryManagerTest.java index 34118458af77..b42ca7b729ae 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/EditorHistoryManagerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/impl/EditorHistoryManagerTest.java @@ -1,6 +1,7 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.fileEditor.impl; +import com.intellij.diagnostic.ThreadDumper; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ex.ApplicationManagerEx; import com.intellij.openapi.components.impl.ComponentManagerImpl; @@ -22,6 +23,7 @@ import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import java.io.File; +import java.lang.ref.WeakReference; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Arrays; @@ -45,11 +47,22 @@ public class EditorHistoryManagerTest extends PlatformTestCase { FileEditorManager.getInstance(project).closeFile(virtualFile); }); + String threadDumpBefore = ThreadDumper.dumpThreadsToString(); + GCUtil.tryGcSoftlyReachableObjects(); + + WeakReference weakReference = new WeakReference<>(new Object()); + do { + //noinspection CallToSystemGC + System.gc(); + } + while (weakReference.get() != null); + Document document = FileDocumentManager.getInstance().getCachedDocument(virtualFile); if (document != null) { fail("Document wasn't collected, see heap dump at " + publishHeapDump(EditorHistoryManagerTest.class.getName())); - System.out.println("Keeping a reference to the document: " + document); + System.err.println("Keeping a reference to the document: " + document); + System.err.println(threadDumpBefore); } openProjectPerformTaskCloseProject(dir, project -> {});