mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
to avoid memory leak drop merged data from disk on finishing every test / or on low memory
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -96,15 +96,19 @@ public class MemoryIndexStorage<Key, Value> implements VfsAwareIndexStorage<Key,
|
||||
|
||||
@Override
|
||||
public void clearCaches() {
|
||||
if (myMap.size() == 0) return;
|
||||
try {
|
||||
if (myMap.size() == 0) return;
|
||||
|
||||
if (DebugAssertions.DEBUG) {
|
||||
String message = "Dropping caches for " + (myIndexId != null ? myIndexId:this) + ", number of items:" + myMap.size();
|
||||
FileBasedIndexImpl.LOG.info(message);
|
||||
}
|
||||
if (DebugAssertions.DEBUG) {
|
||||
String message = "Dropping caches for " + (myIndexId != null ? myIndexId : this) + ", number of items:" + myMap.size();
|
||||
FileBasedIndexImpl.LOG.info(message);
|
||||
}
|
||||
|
||||
for(ChangeTrackingValueContainer<Value> v:myMap.values()) {
|
||||
v.dropMergedData();
|
||||
for (ChangeTrackingValueContainer<Value> v : myMap.values()) {
|
||||
v.dropMergedData();
|
||||
}
|
||||
} finally {
|
||||
myBackendStorage.clearCaches();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Key, Value> implements IndexStorage<Key, V
|
||||
|
||||
@Override
|
||||
public void clearCaches() {
|
||||
|
||||
l.lock();
|
||||
try {
|
||||
for(Map.Entry<Key, ChangeTrackingValueContainer<Value>> entry:myCache.entrySet()) {
|
||||
entry.getValue().dropMergedData();
|
||||
}
|
||||
} finally {
|
||||
l.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
protected static <T> T unwrapCauseAndRethrow(RuntimeException e) throws StorageException {
|
||||
|
||||
Reference in New Issue
Block a user