From 027aa43385fcc184a8fb92bfb33ff019ae4c8109 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 23 Jun 2015 16:31:49 +0200 Subject: [PATCH] clear java bean info cache every 100 tests --- .../intellij/testFramework/LightPlatformTestCase.java | 10 +++++++++- .../testFramework/src/com/intellij/util/GCUtil.java | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 6cd953a3e949..79abae8f7bea 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -94,7 +94,7 @@ import com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl; import com.intellij.psi.templateLanguages.TemplateDataLanguageMappings; import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; import com.intellij.util.Consumer; -import com.intellij.util.IncorrectOperationException; +import com.intellij.util.GCUtil;import com.intellij.util.IncorrectOperationException; import com.intellij.util.LocalTimeCounter; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.FileBasedIndex; @@ -590,7 +590,15 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da checkEditorsReleased(); } documentManager.clearUncommittedDocuments(); + + if (ourTestCount++ % 100 == 0) { + // some tests are written in Groovy, and running all of them may result in some 40M of memory wasted on bean infos + // so let's clear the cache every now and then to ensure it doesn't grow too large + GCUtil.tryClearBeanInfoCache(); + } } + + private static int ourTestCount = 0; public static PsiDocumentManagerImpl clearUncommittedDocuments(@NotNull Project project) { PsiDocumentManagerImpl documentManager = (PsiDocumentManagerImpl)PsiDocumentManager.getInstance(project); diff --git a/platform/testFramework/src/com/intellij/util/GCUtil.java b/platform/testFramework/src/com/intellij/util/GCUtil.java index 86f95b4c49b9..78c1013373fe 100644 --- a/platform/testFramework/src/com/intellij/util/GCUtil.java +++ b/platform/testFramework/src/com/intellij/util/GCUtil.java @@ -81,7 +81,12 @@ public class GCUtil { private static final boolean ourHasBeanInfoCache = SystemInfo.isJavaVersionAtLeast("1.7"); - private static void tryClearBeanInfoCache() { + /** + * Using java beans (e.g. Groovy does it) results in all referenced class infos being cached in ThreadGroupContext. A valid fix + * would be to hold BeanInfo objects on soft references, but that should be done in JDK. So let's clear this cache manually for now, + * in clients that are known to create bean infos. + */ + public static void tryClearBeanInfoCache() { if (ourHasBeanInfoCache) { try { Class aClass = Class.forName("java.beans.ThreadGroupContext");