don't keep help UI in memory after closing the window - it takes more than 60mb (too much for a default Xmx of 512m for 32-bit JDK)

This commit is contained in:
Dmitry Batrak
2016-01-25 13:32:55 +03:00
parent 51063f170f
commit ca1f050e3b
2 changed files with 23 additions and 17 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -27,7 +27,7 @@ import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.help.HelpManager;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.NullableLazyValue;
import com.intellij.reference.SoftReference;
import com.intellij.util.PlatformUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
@@ -35,6 +35,7 @@ import org.jetbrains.annotations.Nullable;
import javax.help.BadIDException;
import javax.help.HelpSet;
import java.awt.*;
import java.lang.ref.WeakReference;
import java.net.URL;
public class HelpManagerImpl extends HelpManager {
@@ -42,14 +43,7 @@ public class HelpManagerImpl extends HelpManager {
@NonNls private static final String HELP_HS = "Help.hs";
private final NullableLazyValue<IdeaHelpBroker> myBrokerValue = new NullableLazyValue<IdeaHelpBroker>() {
@Nullable
@Override
protected IdeaHelpBroker compute() {
HelpSet set = createHelpSet();
return set == null ? null : new IdeaHelpBroker(set);
}
};
private WeakReference<IdeaHelpBroker> myBrokerReference = null;
public void invokeHelp(@Nullable String id) {
UsageTrigger.trigger("ide.help." + id);
@@ -58,7 +52,14 @@ public class HelpManagerImpl extends HelpManager {
return;
}
IdeaHelpBroker broker = myBrokerValue.getValue();
IdeaHelpBroker broker = SoftReference.dereference(myBrokerReference);
if (broker == null) {
HelpSet set = createHelpSet();
if (set != null) {
broker = new IdeaHelpBroker(set);
myBrokerReference = new WeakReference<IdeaHelpBroker>(broker);
}
}
if (broker == null) {
ApplicationInfoEx info = ApplicationInfoEx.getInstanceEx();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -18,6 +18,8 @@ package com.intellij.help.impl;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.ui.AppUIUtil;
import com.intellij.ui.ScreenUtil;
import com.intellij.util.ReflectionUtil;
import com.sun.java.help.impl.JHelpPrintHandler;
import org.jetbrains.annotations.NotNull;
import javax.help.*;
@@ -30,6 +32,7 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.util.Enumeration;
import java.util.Locale;
import java.util.WeakHashMap;
/**
* It a dirty patch! Help system is so ugly that it hangs when it open some "external" links.
@@ -706,11 +709,13 @@ class IdeaHelpBroker extends DefaultHelpBroker implements KeyListener{
AppUIUtil.updateWindowIcon(myFrame);
WindowListener l = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
myFrame.setVisible(false);
}
public void windowClosed(WindowEvent e) {
myFrame.setVisible(false);
myFrame.dispose();
WeakHashMap handlers = ReflectionUtil.getField(JHelpPrintHandler.class, null, WeakHashMap.class, "handlers");
if (handlers != null) {
// even though jHelp is a weak key in the map, corresponding map entry will never be removed, as it's also referenced
// from the mapped value
handlers.remove(jhelp);
}
}
};
myFrame.addWindowListener(l);