mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
remove expired items from LaterInvocator on project close (to minimize project leaks)
This commit is contained in:
+19
-1
@@ -89,7 +89,7 @@ public class LaterInvocator {
|
||||
|
||||
private static final Stack<ModalityState> ourModalityStack = new Stack<>(ModalityState.NON_MODAL);
|
||||
private static final List<RunnableInfo> ourQueue = new ArrayList<>(); //protected by LOCK
|
||||
private static volatile int ourQueueSkipCount; // optimization
|
||||
private static volatile int ourQueueSkipCount; // optimization: should look for next events starting from this index
|
||||
private static final FlushQueue ourFlushQueueRunnable = new FlushQueue();
|
||||
|
||||
private static final EventDispatcher<ModalityStateListener> ourModalityStateMulticaster = EventDispatcher.create(ModalityStateListener.class);
|
||||
@@ -142,6 +142,7 @@ public class LaterInvocator {
|
||||
|
||||
@NotNull
|
||||
static ActionCallback invokeLater(@NotNull Runnable runnable, @NotNull ModalityState modalityState, @NotNull Condition<?> expired) {
|
||||
if (expired.value(null)) return ActionCallback.REJECTED;
|
||||
final ActionCallback callback = new ActionCallback();
|
||||
RunnableInfo runnableInfo = new RunnableInfo(runnable, modalityState, expired, callback);
|
||||
synchronized (LOCK) {
|
||||
@@ -432,4 +433,21 @@ public class LaterInvocator {
|
||||
return ContainerUtil.newArrayList(ourQueue);
|
||||
}
|
||||
}
|
||||
|
||||
public static void purgeExpiredItems() {
|
||||
synchronized (LOCK) {
|
||||
boolean removed = false;
|
||||
for (int i = ourQueue.size() - 1; i >= 0; i--) {
|
||||
RunnableInfo info = ourQueue.get(i);
|
||||
if (info.expired.value(null)) {
|
||||
ourQueue.remove(i);
|
||||
info.callback.setDone();
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
if (removed) {
|
||||
ourQueueSkipCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.notification.NotificationType;
|
||||
import com.intellij.notification.NotificationsManager;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.*;
|
||||
import com.intellij.openapi.application.impl.LaterInvocator;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
@@ -102,6 +103,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements Disposable {
|
||||
listener.projectClosed(project);
|
||||
}
|
||||
ZipHandler.clearFileAccessorCache();
|
||||
LaterInvocator.purgeExpiredItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user