adjusted solution to memory leaks in RubyProjectStructureConfigurable according to...
authorAlexandr Evstigneev <Alexandr.Evstigneev@jetbrains.com>
Thu, 17 Nov 2016 10:43:20 +0000 (13:43 +0300)
committerAlexandr Evstigneev <Alexandr.Evstigneev@jetbrains.com>
Thu, 17 Nov 2016 10:46:11 +0000 (13:46 +0300)
java/debugger/impl/src/com/intellij/debugger/actions/CustomizeContextViewAction.java
platform/platform-impl/src/com/intellij/openapi/options/TabbedConfigurable.java
plugins/generate-tostring/src/org/jetbrains/java/generate/GenerateToStringActionHandlerImpl.java

index 178906b6973547695f9223d56d69ec3f90a1db63..5350cc191dd8014679002a36f0b20630d36c5995 100644 (file)
@@ -20,14 +20,12 @@ import com.intellij.debugger.engine.JavaDebugProcess;
 import com.intellij.debugger.settings.JavaDebuggerSettings;
 import com.intellij.debugger.settings.NodeRendererSettings;
 import com.intellij.idea.ActionsBundle;
-import com.intellij.openapi.Disposable;
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.options.Configurable;
 import com.intellij.openapi.options.ConfigurationException;
 import com.intellij.openapi.options.TabbedConfigurable;
 import com.intellij.openapi.options.ex.SingleConfigurableEditor;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.Disposer;
 import com.intellij.util.ui.JBUI;
 import com.intellij.xdebugger.XDebugSession;
 import com.intellij.xdebugger.XDebuggerManager;
@@ -49,8 +47,7 @@ public class CustomizeContextViewAction extends XDebuggerTreeActionBase {
   @Override
   protected void perform(XValueNodeImpl node, @NotNull String nodeName, AnActionEvent e) {
     final Project project = e.getProject();
-    Disposable disposable = Disposer.newDisposable();
-    final MyTabbedConfigurable configurable = new MyTabbedConfigurable(disposable);
+    final MyTabbedConfigurable configurable = new MyTabbedConfigurable();
     SingleConfigurableEditor editor = new SingleConfigurableEditor(project, configurable) {
       @Override
       protected void doOKAction() {
@@ -66,15 +63,10 @@ public class CustomizeContextViewAction extends XDebuggerTreeActionBase {
         super.doCancelAction();
       }
     };
-    Disposer.register(editor.getDisposable(), disposable);
     editor.show();
   }
 
   private static class MyTabbedConfigurable extends TabbedConfigurable {
-    public MyTabbedConfigurable(@NotNull Disposable parent) {
-      super(parent);
-    }
-
     @Override
     protected List<Configurable> createConfigurables() {
       return JavaDebuggerSettings.createDataViewsConfigurable();
index 59cde1bfc0e946c8820de831f5e7a27463c941ff..39be2062378f6c546ff14cf4a7fb49f594d855c9 100644 (file)
@@ -16,9 +16,9 @@
 package com.intellij.openapi.options;
 
 import com.intellij.openapi.Disposable;
+import com.intellij.openapi.util.Disposer;
 import com.intellij.ui.TabbedPaneWrapper;
 import com.intellij.util.ui.JBUI;
-import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
 
@@ -30,15 +30,11 @@ import static com.intellij.openapi.options.ex.ConfigurableCardPanel.createConfig
 public abstract class TabbedConfigurable extends CompositeConfigurable<Configurable> implements Configurable.NoScroll,
                                                                                                 Configurable.NoMargin {
   protected TabbedPaneWrapper myTabbedPane;
-  private final Disposable myParentDisposable;
-
-  protected TabbedConfigurable(@NotNull Disposable parentDisposable) {
-    myParentDisposable = parentDisposable;
-  }
+  private final Disposable myDisposable = Disposer.newDisposable();
 
   @Override
   public JComponent createComponent() {
-    myTabbedPane = new TabbedPaneWrapper(myParentDisposable);
+    myTabbedPane = new TabbedPaneWrapper(myDisposable);
     createConfigurableTabs();
     final JComponent component = myTabbedPane.getComponent();
     component.setBorder(JBUI.Borders.emptyTop(5));
@@ -54,11 +50,8 @@ public abstract class TabbedConfigurable extends CompositeConfigurable<Configura
 
   @Override
   public void disposeUIResources() {
-    myTabbedPane = null;
     super.disposeUIResources();
-  }
-
-  public Disposable getParentDisposable() {
-    return myParentDisposable;
+    Disposer.dispose(myDisposable);
+    myTabbedPane = null;
   }
 }
index 09885f75221884d47b1561cc1d2fbebd225bdad9..34ca18479d6003369d27be53eb35610500a3d2ed 100644 (file)
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.FileModificationService;
 import com.intellij.codeInsight.generation.PsiElementClassMember;
 import com.intellij.codeInsight.hint.HintManager;
 import com.intellij.ide.util.MemberChooser;
-import com.intellij.openapi.Disposable;
 import com.intellij.openapi.application.WriteAction;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Editor;
@@ -31,7 +30,6 @@ import com.intellij.openapi.options.TabbedConfigurable;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.ComboBox;
 import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.util.Disposer;
 import com.intellij.psi.*;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.psi.util.PsiTreeUtil;
@@ -211,8 +209,7 @@ public class GenerateToStringActionHandlerImpl implements GenerateToStringAction
             settingsButton.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent e) {
                   final TemplatesPanel ui = new TemplatesPanel(clazz.getProject());
-                  Disposable disposable = Disposer.newDisposable();
-                  Configurable composite = new TabbedConfigurable(disposable) {
+                  Configurable composite = new TabbedConfigurable() {
                         protected List<Configurable> createConfigurables() {
                             List<Configurable> res = new ArrayList<>();
                             res.add(new GenerateToStringConfigurable(clazz.getProject()));
@@ -242,7 +239,7 @@ public class GenerateToStringActionHandlerImpl implements GenerateToStringAction
                     };
 
                     ShowSettingsUtil.getInstance().editConfigurable(MemberChooserHeaderPanel.this, composite, () -> ui.selectItem(ToStringTemplatesManager.getInstance().getDefaultTemplate()));
-                  Disposer.dispose(disposable);
+                  composite.disposeUIResources();
                 }
             });