diff --git a/platform/platform-impl/src/com/intellij/help/impl/HelpManagerImpl.java b/platform/platform-impl/src/com/intellij/help/impl/HelpManagerImpl.java index e55f9f1e54bc..9d527a91540a 100644 --- a/platform/platform-impl/src/com/intellij/help/impl/HelpManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/help/impl/HelpManagerImpl.java @@ -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 myBrokerValue = new NullableLazyValue() { - @Nullable - @Override - protected IdeaHelpBroker compute() { - HelpSet set = createHelpSet(); - return set == null ? null : new IdeaHelpBroker(set); - } - }; + private WeakReference 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(broker); + } + } if (broker == null) { ApplicationInfoEx info = ApplicationInfoEx.getInstanceEx(); diff --git a/platform/platform-impl/src/com/intellij/help/impl/IdeaHelpBroker.java b/platform/platform-impl/src/com/intellij/help/impl/IdeaHelpBroker.java index 00dca171ae84..4b5e5d87c232 100644 --- a/platform/platform-impl/src/com/intellij/help/impl/IdeaHelpBroker.java +++ b/platform/platform-impl/src/com/intellij/help/impl/IdeaHelpBroker.java @@ -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);