From ad90be2ffb50b62b3845f8caff6802974ccb2e2d Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Thu, 17 Oct 2013 14:52:21 +0300 Subject: [PATCH] Fixes releasing plugin components when the strong value is referring the key and cannot be released. --- .../service/gui/PluginComponentFactory.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/net/java/sip/communicator/service/gui/PluginComponentFactory.java b/src/net/java/sip/communicator/service/gui/PluginComponentFactory.java index 0608b4e8d..56ab2fc5f 100644 --- a/src/net/java/sip/communicator/service/gui/PluginComponentFactory.java +++ b/src/net/java/sip/communicator/service/gui/PluginComponentFactory.java @@ -6,6 +6,7 @@ */ package net.java.sip.communicator.service.gui; +import java.lang.ref.*; import java.util.*; /** @@ -41,8 +42,8 @@ public abstract class PluginComponentFactory * Weak hash map holding plugins if the parent (container) is garbage * collected free and the plugin instance that corresponds it. */ - private WeakHashMap pluginInstances = - new WeakHashMap(); + private WeakHashMap> pluginInstances = + new WeakHashMap>(); /** * Creates a default factory for a container. @@ -133,16 +134,17 @@ public boolean isNativeComponent() * * @return the component that should be added. */ + @SuppressWarnings("unchecked") public PluginComponent getPluginComponentInstance(Object parent) { - PluginComponent p = pluginInstances.get(parent); + WeakReference p = pluginInstances.get(parent); if(p == null) { - p = getPluginInstance(); + p = new WeakReference(getPluginInstance()); pluginInstances.put(parent, p); } - return p; + return p.get(); } /**