From 446b80077aed71e2384301ae993cf44416bf9a83 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 1 Jun 2016 07:30:23 +0200 Subject: [PATCH] clean up AstPath objects when no PSI is accessed, e.g. after project closing --- .../com/intellij/psi/impl/source/AstPathPsiMap.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/AstPathPsiMap.java b/platform/core-impl/src/com/intellij/psi/impl/source/AstPathPsiMap.java index 50764706ca1e..0be43afc1577 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/AstPathPsiMap.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/AstPathPsiMap.java @@ -15,6 +15,7 @@ */ package com.intellij.psi.impl.source; +import com.intellij.concurrency.JobScheduler; import com.intellij.extapi.psi.StubBasedPsiElementBase; import com.intellij.psi.impl.source.tree.AstPath; import com.intellij.psi.impl.source.tree.CompositeElement; @@ -26,6 +27,7 @@ import org.jetbrains.annotations.Nullable; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.TimeUnit; /** * A weak cache for all instantiated stub-based PSI to allow {@link CompositeElement#getPsi()} return it when AST is reloaded.

@@ -39,6 +41,16 @@ class AstPathPsiMap { */ private final ConcurrentMap myMap = ContainerUtil.newConcurrentMap(); + static { + JobScheduler.getScheduler().scheduleWithFixedDelay(new Runnable() { + @Override + public void run() { + // clean up AstPath objects when no PSI is accessed, e.g. after project closing + processQueue(); + } + }, 5, 5, TimeUnit.SECONDS); + } + void invalidatePsi() { processQueue(); for (MyReference reference : myMap.values()) {