From 67fb24a7fd1e7d2d573a099f54375f37c96d43ee Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Fri, 27 Feb 2015 01:56:36 +0100 Subject: [PATCH] swf disposing fixes --- .../src/com/jpexs/decompiler/flash/SWF.java | 29 +++++++++++++++++++ .../src/com/jpexs/helpers/Cache.java | 23 ++++++++++----- .../decompiler/flash/gui/ImagePanel.java | 1 + .../jpexs/decompiler/flash/gui/MainPanel.java | 6 ++++ .../decompiler/flash/gui/abc/ABCPanel.java | 1 + .../flash/gui/abc/DecompiledEditorPane.java | 4 +++ 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index d510f530a..9f182af97 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -303,6 +303,35 @@ public final class SWF implements SWFContainerItem, Timelined { characters = null; } + public void clearTagSwfs() { + resetTimelines(this); + updateCharacters(); + + for (Tag tag : tags) { + if (tag instanceof DefineSpriteTag) { + DefineSpriteTag spriteTag = (DefineSpriteTag) tag; + for (Tag tag1 : spriteTag.subTags) { + tag1.setSwf(null); + } + + spriteTag.subTags.clear(); + } + + tag.setSwf(null); + } + + tags.clear(); + abcList.clear(); + + as2Cache.clear(); + as3Cache.clear(); + + timeline = null; + dumpInfo = null; + jtt = null; + binaryData = null; + } + public Map getCharacters() { if (characters == null) { synchronized (this) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java index d5c2255d8..66be69938 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java @@ -19,6 +19,7 @@ package com.jpexs.helpers; import com.jpexs.decompiler.flash.helpers.Freed; import java.io.File; import java.io.IOException; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -35,7 +36,7 @@ public class Cache implements Freed { private Map cache; - private static final List instances = new ArrayList<>(); + private static final List> instances = new ArrayList<>(); public static final int STORAGE_FILES = 1; @@ -52,9 +53,12 @@ public class Cache implements Freed { @Override public void run() { - for (Cache c : instances) { - c.clear(); - c.free(); + for (WeakReference cw : instances) { + Cache c = cw.get(); + if (c != null) { + c.clear(); + c.free(); + } } } @@ -63,16 +67,19 @@ public class Cache implements Freed { public static Cache getInstance(boolean weak, boolean memoryOnly, String name) { Cache instance = new Cache<>(weak, memoryOnly, name); - instances.add(instance); + instances.add(new WeakReference(instance)); return instance; } private static int storageType = STORAGE_FILES; public static void clearAll() { - for (Cache c : instances) { - c.clear(); - c.initCache(); + for (WeakReference cw : instances) { + Cache c = cw.get(); + if (c != null) { + c.clear(); + c.initCache(); + } } } diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 481eda4c7..57c280ec5 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -855,6 +855,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis public synchronized void clearAll() { stop(); + clearImagePanel(); timelined = null; swf = null; } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 60faffabf..4b9c321c5 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -725,6 +725,11 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } + /*for (SWFList swfList : swfs) { + for (SWF swf : swfList) { + swf.clearTagSwfs(); + } + }*/ swfs.clear(); oldItem = null; previewPanel.clear(); @@ -2442,6 +2447,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec @Override public void run() { + setSourceWorker = null; try { get(); } catch (CancellationException ex) { diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 3b5f3e282..76c3da776 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -286,6 +286,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se this.abc = null; constantTable.setModel(new DefaultTableModel()); navigator.clearAbc(); + decompiledTextArea.clearScript(); } public void initSplits() { diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 1ada9ccd1..468f2f1a0 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -639,6 +639,10 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL this.abcPanel = abcPanel; } + public void clearScript() { + script = null; + } + public void setScript(ScriptPack scriptLeaf) { abcPanel.scriptNameLabel.setText(scriptLeaf.getClassPath().toString()); int scriptIndex = scriptLeaf.scriptIndex;