From dc28ce5da780783f023b19ece3dc84b880c4fd5d Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 25 May 2015 16:16:55 +0200 Subject: [PATCH] free mainpanel on reload (it is not disposed by java GC for some reason) --- .../src/com/jpexs/helpers/Helper.java | 26 +++++++++++-------- .../flash/gui/MainFrameClassic.java | 1 + .../decompiler/flash/gui/MainFrameRibbon.java | 1 + .../jpexs/decompiler/flash/gui/MainPanel.java | 18 +++++++++++++ 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index 594cddb62..9dd0f1976 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -786,20 +786,24 @@ public class Helper { f.setAccessible(true); Object v = f.get(obj); if (v != null) { - if (v instanceof Collection) { - ((Collection) v).clear(); - } - if (v instanceof Component) { - if (((Component) v).getParent() != null) { - ((Component) v).getParent().remove((Component) v); + try { + if (v instanceof Collection) { + ((Collection) v).clear(); } - } - if (v instanceof Freed) { - Freed freed = ((Freed) v); - if (!freed.isFreeing()) { - ((Freed) v).free(); + if (v instanceof Component) { + if (((Component) v).getParent() != null) { + ((Component) v).getParent().remove((Component) v); + } } + if (v instanceof Freed) { + Freed freed = ((Freed) v); + if (!freed.isFreeing()) { + ((Freed) v).free(); + } + } + } catch (Throwable t) { } + f.set(obj, null); } } catch (UnsupportedOperationException | SecurityException | IllegalArgumentException | IllegalAccessException ex) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java index 703e83e3d..30671750d 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java @@ -126,6 +126,7 @@ public final class MainFrameClassic extends AppFrame implements MainFrame { public void dispose() { removeAll(); mainMenu.dispose(); + panel.dispose(); super.dispose(); } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java index bf99d7cf5..86c5d6459 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java @@ -173,6 +173,7 @@ public final class MainFrameRibbon extends AppRibbonFrame { public void dispose() { removeAll(); mainMenu.dispose(); + panel.dispose(); super.dispose(); } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 7e874c1ef..1a47b835e 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -141,6 +141,7 @@ import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; +import java.awt.Container; import java.awt.Desktop; import java.awt.FlowLayout; import java.awt.Font; @@ -3208,4 +3209,21 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } }; } + + private void disposeInner(Container container) { + for (Component c : container.getComponents()) { + if (c instanceof Container) { + Container c2 = (Container) c; + disposeInner(c2); + } + } + + container.removeAll(); + container.setLayout(null); + Helper.emptyObject(container); + } + + public void dispose() { + disposeInner(this); + } }