Do not leak LowMemoryWatcher on plugin unload

#KT-44543 Fixed
This commit is contained in:
Vladimir Dolzhenko
2021-01-26 14:25:04 +01:00
committed by Space
parent 76c2288e21
commit 8019dbe06c
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.resolve.jvm; package org.jetbrains.kotlin.resolve.jvm;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.DumbService;
@@ -58,7 +59,7 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
public class KotlinJavaPsiFacade { public class KotlinJavaPsiFacade implements Disposable {
private volatile KotlinPsiElementFinderWrapper[] elementFinders; private volatile KotlinPsiElementFinderWrapper[] elementFinders;
private static class PackageCache { private static class PackageCache {
@@ -96,9 +97,9 @@ public class KotlinJavaPsiFacade {
emptyModifierList = new LightModifierList(PsiManager.getInstance(project), KotlinLanguage.INSTANCE); emptyModifierList = new LightModifierList(PsiManager.getInstance(project), KotlinLanguage.INSTANCE);
// drop entire cache when it is low free memory // drop entire cache when it is low free memory
LowMemoryWatcher.register(this::clearPackageCaches, project); LowMemoryWatcher.register(this::clearPackageCaches, this);
MessageBusConnection connection = project.getMessageBus().connect(); MessageBusConnection connection = project.getMessageBus().connect(this);
// VFS changes like create/delete/copy/move directory are subject to clean up short term caches // VFS changes like create/delete/copy/move directory are subject to clean up short term caches
connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() { connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@@ -139,6 +140,11 @@ public class KotlinJavaPsiFacade {
}); });
} }
@Override
public void dispose() {
clearPackageCaches();
}
public void clearPackageCaches() { public void clearPackageCaches() {
clearPackageCaches(true); clearPackageCaches(true);
} }