free mainpanel on reload (it is not disposed by java GC for some reason)

This commit is contained in:
honfika@gmail.com
2015-05-25 16:16:55 +02:00
parent 134fd1558a
commit dc28ce5da7
4 changed files with 35 additions and 11 deletions

View File

@@ -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) {

View File

@@ -126,6 +126,7 @@ public final class MainFrameClassic extends AppFrame implements MainFrame {
public void dispose() {
removeAll();
mainMenu.dispose();
panel.dispose();
super.dispose();
}
}

View File

@@ -173,6 +173,7 @@ public final class MainFrameRibbon extends AppRibbonFrame {
public void dispose() {
removeAll();
mainMenu.dispose();
panel.dispose();
super.dispose();
}
}

View File

@@ -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);
}
}