project leak via toolbar->icon->DeferredIcon.evaluator->RunManager$1->project

This commit is contained in:
Alexey Kudravtsev
2015-11-03 14:29:35 +03:00
parent 2edc67d3eb
commit 5e296a4d2e
2 changed files with 17 additions and 10 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,19 +17,19 @@ package com.intellij.openapi.actionSystem.impl;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import java.util.WeakHashMap;
import java.util.Map;
public class PresentationFactory {
private final WeakHashMap<AnAction,Presentation> myAction2Presentation;
public PresentationFactory() {
myAction2Presentation = new WeakHashMap<AnAction, Presentation>();
}
// Presentation can leak icon which can leak com.intellij.ui.DeferredIconImpl.myEvaluator which can leak enclosing class instance which can leak Project
private final Map<AnAction, Presentation> myAction2Presentation = ContainerUtil.createWeakKeySoftValueMap();
@NotNull
public final Presentation getPresentation(@NotNull AnAction action){
ApplicationManager.getApplication().assertIsDispatchThread();
Presentation presentation = myAction2Presentation.get(action);
if (presentation == null || !action.isDefaultIcon()){
Presentation templatePresentation = action.getTemplatePresentation();
@@ -50,6 +50,7 @@ public class PresentationFactory {
}
public void reset() {
ApplicationManager.getApplication().assertIsDispatchThread();
myAction2Presentation.clear();
}
}
@@ -147,6 +147,7 @@ public class IdeRootPane extends JRootPane implements UISettingsListener {
*/
public final void removeNotify(){
myUISettings.removeUISettingsListener(this);
removeToolbar();
super.removeNotify();
}
@@ -187,15 +188,20 @@ public class IdeRootPane extends JRootPane implements UISettingsListener {
}
void updateToolbar() {
if (myToolbar != null) {
myNorthPanel.remove(myToolbar);
}
removeToolbar();
myToolbar = createToolbar();
myNorthPanel.add(myToolbar, 0);
updateToolbarVisibility();
myContentPane.revalidate();
}
private void removeToolbar() {
if (myToolbar != null) {
myNorthPanel.remove(myToolbar);
myToolbar = null;
}
}
void updateNorthComponents() {
for (IdeRootPaneNorthExtension northComponent : myNorthComponents) {
northComponent.revalidate();