Just one file, ECUEditor.java needs to be updated to fix the memory leak. Here's the important part:
Code:
@@ -195,15 +198,20 @@
public void closeImage() {
for (int i = 0; i < imageRoot.getChildCount(); i++) {
- if (((RomTreeNode)imageRoot.getChildAt(i)).getRom() == lastSelectedRom) {
-
- for (int j = 0; j < getImages().get(i).getTables().size(); j++) {
- rightPanel.remove(((Table)getImages().get(i).getTables().get(i)).getFrame());
- }
-
- ((Rom)getImages().get(i)).closeImage();
- imageRoot.remove((RomTreeNode)imageRoot.getChildAt(i));
- getImages().remove(i);
+ RomTreeNode romTreeNode = (RomTreeNode)imageRoot.getChildAt(i);
+ Rom rom = romTreeNode.getRom();
+ if (rom == lastSelectedRom) {
+ Vector<Table> romTables = rom.getTables();
+ for (Iterator j = romTables.iterator(); j.hasNext();) {
+ Table t = (Table)j.next();
+ rightPanel.remove(t.getFrame());
+ }
+ rom.closeImage();
+ romTreeNode.setRom(null);
+ romTreeNode.removeAllChildren();
+ images.remove(i);
+ imageRoot.remove(romTreeNode);
+ break;
}
}
imageList.updateUI();
The real key is romTreeNode.removeAllChildren(), the rest of it is just being thorough and making it a bit easier for me to follow.
Also there appeared to be a bug in the original line
Code:
rightPanel.remove(((Table)getImages().get(i).getTables().get(i)).getFrame());
The second i should probably be j, but in my version I replaced that loop with an Iterator.
Note the added break once the last selected ROM is found, no need to cycle through any more once the selected ROM is closed.
Also to note, there are a number of places in various source files where you call
Code:
new JOptionPane().showMessageDialog
Creating a new JOptionPane is not necessary since showMessageDialog is static. On a similar note, there are cases where you access a static variable in a non-static way (see JCheckBox.RIGHT).
Here's a diff for ECUEditor.java showing the change in this file, all the other references should be modified similarly. I've attached a zip file which has the modified source I ended up with. Have a look with WinMerge and let me know if you have any questions.
Code:
@@ -63,7 +67,7 @@
Document doc = parser.getDocument();
settings = domUms.unmarshallSettings(doc.getDocumentElement());
} catch (Exception ex) {
- new JOptionPane().showMessageDialog(this, "Settings file not found.\n" +
+ JOptionPane.showMessageDialog(this, "Settings file not found.\n" +
"A new file will be created.", "Error Loading Settings", JOptionPane.INFORMATION_MESSAGE);
}
infoPanel.add(new URL(getSettings().getRomRevisionURL()));
JCheckBox check = new JCheckBox("Always display this message", true);
- check.setHorizontalAlignment(check.RIGHT);
+ check.setHorizontalAlignment(JCheckBox.RIGHT);
check.addActionListener(
new ActionListener() {
@@ -171,7 +174,7 @@
);
infoPanel.add(check);
- new JOptionPane().showMessageDialog(this, infoPanel, "ECU Revision is Obsolete", JOptionPane.INFORMATION_MESSAGE);
+ JOptionPane.showMessageDialog(this, infoPanel, "ECU Revision is Obsolete", JOptionPane.INFORMATION_MESSAGE);
}
input.setContainer(this);
}