use more sane API for LowMemoryWatcher

This commit is contained in:
Alexey Kudravtsev
2016-07-06 14:55:03 +03:00
parent 1cf3d6d91b
commit 27d1def099
3 changed files with 20 additions and 14 deletions
@@ -44,12 +44,6 @@ import java.util.*;
public class SmartPointerManagerImpl extends SmartPointerManager {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.smartPointers.SmartPointerManagerImpl");
private static final ReferenceQueue<SmartPsiElementPointerImpl> ourQueue = new ReferenceQueue<SmartPsiElementPointerImpl>();
@SuppressWarnings("unused") private static final LowMemoryWatcher ourWatcher = LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
processQueue();
}
});
private final Project myProject;
private final Key<FilePointersList> POINTERS_KEY;
@@ -61,6 +55,15 @@ public class SmartPointerManagerImpl extends SmartPointerManager {
POINTERS_KEY = Key.create("SMART_POINTERS for "+project);
}
static {
LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
processQueue();
}
}, ApplicationManager.getApplication());
}
private static void processQueue() {
while (true) {
PointerReference reference = (PointerReference)ourQueue.poll();
@@ -49,7 +49,7 @@ class AstPathPsiMap {
AstPathPsiMap(@NotNull Project project) {
MyReferenceQueue queue = project.getUserData(STUB_PSI_REFS);
myQueue = queue != null ? queue : ((UserDataHolderEx)project).putUserDataIfAbsent(STUB_PSI_REFS, new MyReferenceQueue());
myQueue = queue != null ? queue : ((UserDataHolderEx)project).putUserDataIfAbsent(STUB_PSI_REFS, new MyReferenceQueue(project));
}
void invalidatePsi() {
@@ -100,12 +100,14 @@ class AstPathPsiMap {
}
private static class MyReferenceQueue extends ReferenceQueue<StubBasedPsiElementBase<?>> {
@SuppressWarnings("unused") LowMemoryWatcher watcher = LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
cleanupStaleReferences();
}
});
MyReferenceQueue(Project project) {
LowMemoryWatcher.register(new Runnable() {
@Override
public void run() {
cleanupStaleReferences();
}
},project);
}
void cleanupStaleReferences() {
while (true) {
@@ -56,7 +56,7 @@ public class CompressedAppendableFile {
private static final int myMinAppendBufferLength = 1024;
public static final String INCOMPLETE_CHUNK_LENGTH_FILE_EXTENSION = ".s";
@SuppressWarnings("unused") private final LowMemoryWatcher myLowMemoryWatcher;
private final LowMemoryWatcher myLowMemoryWatcher;
public CompressedAppendableFile(File file) {
this(file, PersistentBTreeEnumerator.PAGE_SIZE);
@@ -434,6 +434,7 @@ public class CompressedAppendableFile {
}
public synchronized void dispose() {
myLowMemoryWatcher.stop();
force();
}