Skip to content

Commit bf89d42

Browse files
committed
Mostly solved memory leak
1 parent 8060c46 commit bf89d42

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/java/com/javadeobfuscator/deobfuscator/ui/SwingWindow.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,7 @@ public void run()
871871
textPane.setText(stringWriter.toString());
872872
newFrame.setVisible(true);
873873
}
874+
deob.clearClasses();
874875
}
875876
});
876877
thread.start();
@@ -883,7 +884,10 @@ public void windowClosing(WindowEvent e)
883884
area.setText(null);
884885
run.setEnabled(true);
885886
if(thread.isAlive())
887+
{
886888
thread.stop();
889+
deob.clearClasses();
890+
}
887891
e.getWindow().dispose();
888892
}
889893
});

src/java/com/javadeobfuscator/deobfuscator/ui/wrap/Deobfuscator.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import java.io.*;
44
import java.lang.reflect.Constructor;
5+
import java.lang.reflect.Field;
56
import java.lang.reflect.Method;
7+
import java.util.Map;
8+
import java.util.Set;
69

710
import com.javadeobfuscator.deobfuscator.ui.util.*;
811

@@ -15,6 +18,10 @@ public class Deobfuscator {
1518
* Config wrapper to use in deobfuscator.
1619
*/
1720
private Config config;
21+
/**
22+
* The deobfuscator instance.
23+
*/
24+
private Object instance;
1825

1926
Deobfuscator(ByteLoader loader) {
2027
this.loader = loader;
@@ -62,10 +69,53 @@ public void run() throws Exception {
6269
Config conf = getConfig();
6370
Constructor<?> con = main.getDeclaredConstructor(conf.get().getClass());
6471
Object deob = con.newInstance(conf.get());
72+
instance = deob;
6573
Method start = main.getMethod("start");
6674
start.invoke(deob);
6775
}
6876

77+
/**
78+
* Clears the classes in the main deobfuscator class.
79+
*
80+
* @throws Exception
81+
* Thrown for any failure in the deobfuscator.
82+
*/
83+
public void clearClasses()
84+
{
85+
try
86+
{
87+
if(instance != null)
88+
{
89+
Class<?> main = loader.findClass("com.javadeobfuscator.deobfuscator.Deobfuscator");
90+
Field cp = main.getDeclaredField("classpath");
91+
cp.setAccessible(true);
92+
((Map<?, ?>)cp.get(instance)).clear();
93+
Field c = main.getDeclaredField("classes");
94+
c.setAccessible(true);
95+
((Map<?, ?>)c.get(instance)).clear();
96+
Field h = main.getDeclaredField("hierachy");
97+
h.setAccessible(true);
98+
((Map<?, ?>)h.get(instance)).clear();
99+
Field ip = main.getDeclaredField("inputPassthrough");
100+
ip.setAccessible(true);
101+
((Map<?, ?>)ip.get(instance)).clear();
102+
Field cps = main.getDeclaredField("constantPools");
103+
cps.setAccessible(true);
104+
((Map<?, ?>)cps.get(instance)).clear();
105+
Field r = main.getDeclaredField("readers");
106+
r.setAccessible(true);
107+
((Map<?, ?>)r.get(instance)).clear();
108+
Field lc = main.getDeclaredField("libraryClassnodes");
109+
lc.setAccessible(true);
110+
((Set<?>)lc.get(instance)).clear();
111+
instance = null;
112+
}
113+
}catch(Exception e)
114+
{
115+
e.printStackTrace();
116+
}
117+
}
118+
69119
/**
70120
* Intercept logging calls.
71121
*

0 commit comments

Comments
 (0)