diff --git a/platform/util/src/com/intellij/util/ref/GCUtil.java b/platform/util/src/com/intellij/util/ref/GCUtil.java index c3c05c4a493e..0f8f2ea7c2b9 100644 --- a/platform/util/src/com/intellij/util/ref/GCUtil.java +++ b/platform/util/src/com/intellij/util/ref/GCUtil.java @@ -32,7 +32,7 @@ public class GCUtil { * In tests, if you can exactly point to objects you want to GC, use {@code GCWatcher.tracking(objects).tryGc()} * which is faster and has more chances to succeed. *
- * Commits / hours of tweaking method code: 7 / 6 + * Commits / hours of tweaking method code: 10 / 6 */ @TestOnly public static void tryGcSoftlyReachableObjects() { diff --git a/platform/util/src/com/intellij/util/ref/GCWatcher.java b/platform/util/src/com/intellij/util/ref/GCWatcher.java index 896de1906bf6..e07c07162f69 100644 --- a/platform/util/src/com/intellij/util/ref/GCWatcher.java +++ b/platform/util/src/com/intellij/util/ref/GCWatcher.java @@ -2,6 +2,7 @@ package com.intellij.util.ref; import com.intellij.openapi.util.Ref; +import com.intellij.reference.SoftReference; import com.intellij.util.MemoryDumpHelper; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Contract; @@ -73,6 +74,9 @@ public class GCWatcher { */ public void tryGc() { if (!GCUtil.allocateTonsOfMemory(this::isEverythingCollected)) { + String message = "Couldn't garbage-collect some objects, they might still be reachable from GC roots: " + + ContainerUtil.mapNotNull(myReferences, SoftReference::dereference); + try { File file = new File(System.getProperty("teamcity.build.tempDir", System.getProperty("java.io.tmpdir")), "GCWatcher.hprof.zip"); MemoryDumpHelper.captureMemoryDumpZipped(file); @@ -83,7 +87,7 @@ public class GCWatcher { catch (Exception e) { throw new RuntimeException(e); } - throw new IllegalStateException("Couldn't garbage-collect all passed objects, they might still be reachable from GC roots"); + throw new IllegalStateException(message); } }