未验证 提交 dcf4a7c4 编写于 作者: S Skylot

fix(gui): try to resolve some causes of memory leak

上级 9ba07b98
...@@ -437,6 +437,7 @@ public class MainWindow extends JFrame { ...@@ -437,6 +437,7 @@ public class MainWindow extends JFrame {
LogCollector.getInstance().reset(); LogCollector.getInstance().reset();
wrapper.close(); wrapper.close();
tabbedPane.closeAllTabs(); tabbedPane.closeAllTabs();
UiUtils.resetClipboardOwner();
System.gc(); System.gc();
} }
......
...@@ -373,49 +373,56 @@ public class TabbedPane extends JTabbedPane { ...@@ -373,49 +373,56 @@ public class TabbedPane extends JTabbedPane {
jumps.reset(); jumps.reset();
curTab = null; curTab = null;
lastTab = null; lastTab = null;
FocusManager.reset();
} }
@Nullable @Nullable
public Component getFocusedComp() { public Component getFocusedComp() {
return FocusManager.isActive() ? FocusManager.focusedComp : null; return FocusManager.getFocusedComp();
} }
private static class FocusManager implements FocusListener { private static class FocusManager implements FocusListener {
static boolean active = false; private static final FocusManager INSTANCE = new FocusManager();
static FocusManager listener = new FocusManager(); private static @Nullable Component focusedComp;
static Component focusedComp;
static boolean isActive() { static boolean isActive() {
return active; return focusedComp != null;
}
static void reset() {
focusedComp = null;
}
static Component getFocusedComp() {
return focusedComp;
} }
@Override @Override
public void focusGained(FocusEvent e) { public void focusGained(FocusEvent e) {
active = true;
focusedComp = (Component) e.getSource(); focusedComp = (Component) e.getSource();
} }
@Override @Override
public void focusLost(FocusEvent e) { public void focusLost(FocusEvent e) {
active = false; focusedComp = null;
} }
static void listen(ContentPanel pane) { static void listen(ContentPanel pane) {
if (pane instanceof ClassCodeContentPanel) { if (pane instanceof ClassCodeContentPanel) {
((ClassCodeContentPanel) pane).getCodeArea().addFocusListener(listener); ((ClassCodeContentPanel) pane).getCodeArea().addFocusListener(INSTANCE);
((ClassCodeContentPanel) pane).getSmaliCodeArea().addFocusListener(listener); ((ClassCodeContentPanel) pane).getSmaliCodeArea().addFocusListener(INSTANCE);
return; return;
} }
if (pane instanceof AbstractCodeContentPanel) { if (pane instanceof AbstractCodeContentPanel) {
((AbstractCodeContentPanel) pane).getCodeArea().addFocusListener(listener); ((AbstractCodeContentPanel) pane).getCodeArea().addFocusListener(INSTANCE);
return; return;
} }
if (pane instanceof HtmlPanel) { if (pane instanceof HtmlPanel) {
((HtmlPanel) pane).getHtmlArea().addFocusListener(listener); ((HtmlPanel) pane).getHtmlArea().addFocusListener(INSTANCE);
return; return;
} }
if (pane instanceof ImagePanel) { if (pane instanceof ImagePanel) {
pane.addFocusListener(listener); pane.addFocusListener(INSTANCE);
return; return;
} }
// throw new JadxRuntimeException("Add the new ContentPanel to TabbedPane.FocusManager: " + pane); // throw new JadxRuntimeException("Add the new ContentPanel to TabbedPane.FocusManager: " + pane);
......
...@@ -147,6 +147,7 @@ public class SearchDialog extends CommonSearchDialog { ...@@ -147,6 +147,7 @@ public class SearchDialog extends CommonSearchDialog {
if (searchDisposable != null && !searchDisposable.isDisposed()) { if (searchDisposable != null && !searchDisposable.isDisposed()) {
searchDisposable.dispose(); searchDisposable.dispose();
} }
resultsModel.clear();
removeActiveTabListener(); removeActiveTabListener();
super.dispose(); super.dispose();
} }
...@@ -399,6 +400,7 @@ public class SearchDialog extends CommonSearchDialog { ...@@ -399,6 +400,7 @@ public class SearchDialog extends CommonSearchDialog {
if (searchTask != null) { if (searchTask != null) {
searchTask.cancel(); searchTask.cancel();
searchTask.waitTask(); searchTask.waitTask();
searchTask = null;
} }
} }
......
...@@ -329,6 +329,23 @@ public class UiUtils { ...@@ -329,6 +329,23 @@ public class UiUtils {
} }
} }
/**
* Owner field in Clipboard class can store reference to CodeArea.
* This prevents from garbage collection whole jadx object tree and cause memory leak.
* Trying to lost ownership by new empty selection.
*/
public static void resetClipboardOwner() {
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemSelection();
if (clipboard != null) {
StringSelection selection = new StringSelection("");
clipboard.setContents(selection, selection);
}
} catch (Exception e) {
LOG.error("Failed to reset clipboard owner", e);
}
}
public static int calcProgress(ITaskProgress taskProgress) { public static int calcProgress(ITaskProgress taskProgress) {
return calcProgress(taskProgress.progress(), taskProgress.total()); return calcProgress(taskProgress.progress(), taskProgress.total());
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册