From a00547672d52293f584f96ca163417d91513a2ca Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Wed, 25 Jan 2017 07:27:38 +0100 Subject: [PATCH] to avoid memory leak drop merged data from disk on finishing every test / or on low memory --- .../util/indexing/FileBasedIndexImpl.java | 13 +++++++++++++ .../util/indexing/MemoryIndexStorage.java | 18 +++++++++++------- .../util/indexing/impl/MapIndexStorage.java | 10 +++++++++- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java index a5426a4df689..aa5a8762c8cb 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndexImpl.java @@ -943,6 +943,19 @@ public class FileBasedIndexImpl extends FileBasedIndex { @TestOnly public void cleanupForNextTest() { myTransactionMap = SmartFMap.emptyMap(); + IndexConfiguration state = getState(); + for (ID indexId : state.getIndexIDs()) { + final MapReduceIndex index = (MapReduceIndex)state.getIndex(indexId); + assert index != null; + final MemoryIndexStorage memStorage = (MemoryIndexStorage)index.getStorage(); + index.getWriteLock().lock(); + try { + memStorage.clearCaches(); + } + finally { + index.getWriteLock().unlock(); + } + } } @TestOnly diff --git a/platform/lang-impl/src/com/intellij/util/indexing/MemoryIndexStorage.java b/platform/lang-impl/src/com/intellij/util/indexing/MemoryIndexStorage.java index 8ebced5856b4..d289a4d647e0 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/MemoryIndexStorage.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/MemoryIndexStorage.java @@ -96,15 +96,19 @@ public class MemoryIndexStorage implements VfsAwareIndexStorage v:myMap.values()) { - v.dropMergedData(); + for (ChangeTrackingValueContainer v : myMap.values()) { + v.dropMergedData(); + } + } finally { + myBackendStorage.clearCaches(); } } diff --git a/platform/util/src/com/intellij/util/indexing/impl/MapIndexStorage.java b/platform/util/src/com/intellij/util/indexing/impl/MapIndexStorage.java index 79278aa1016a..976d2aa2a519 100644 --- a/platform/util/src/com/intellij/util/indexing/impl/MapIndexStorage.java +++ b/platform/util/src/com/intellij/util/indexing/impl/MapIndexStorage.java @@ -27,6 +27,7 @@ import org.jetbrains.annotations.TestOnly; import java.io.File; import java.io.IOException; +import java.util.Map; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -243,7 +244,14 @@ public abstract class MapIndexStorage implements IndexStorage> entry:myCache.entrySet()) { + entry.getValue().dropMergedData(); + } + } finally { + l.unlock(); + } } protected static T unwrapCauseAndRethrow(RuntimeException e) throws StorageException {