Fix memory leak for good.

Whenever we close a ROM image, we need to make a call to RomTree.clearToggledPaths.
That clears the RomTree.expandedState (RomTree extends JTree) which was holding
onto references of RomTreeNodes.
Now that the memory leak is fixed, we can remove the other cleanup() function
hacks and the explicit call to System.gc().


git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@103 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
drees 2006-07-08 08:33:05 +00:00
parent a7dbfed8eb
commit 94f345052a
5 changed files with 19 additions and 58 deletions

View File

@ -232,22 +232,23 @@ public class ECUEditor extends JFrame implements WindowListener, PropertyChangeL
}
public void closeImage() {
for (int i = 0; i < imageRoot.getChildCount(); 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());
t.cleanup();
}
imageRoot.remove(i);
romTreeNode.cleanup();
break;
}
}
for (int i = 0; i < imageRoot.getChildCount(); 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());
}
imageRoot.remove(i);
break;
}
}
imageList.cleanup();
imageList.updateUI();
if (imageRoot.getChildCount() > 0) {
setLastSelectedRom(((RomTreeNode)imageRoot.getChildAt(0)).getRom());
} else {
@ -255,7 +256,6 @@ public class ECUEditor extends JFrame implements WindowListener, PropertyChangeL
setLastSelectedRom(null);
}
rightPanel.repaint();
System.gc();
}
public void closeAllImages() {

View File

@ -128,22 +128,6 @@ public class Rom implements Serializable {
return binData;
}
public void cleanup() {
try {
container = null;
binData = null;
romID = null;
for (int i = 0; i < tables.size(); i++) {
tables.get(i).getFrame().dispose();
}
tables.clear();
tables = null;
}
catch (Throwable t) {
t.printStackTrace();
}
}
public int getRealFileSize() {
return binData.length;
}

View File

@ -919,16 +919,6 @@ public abstract class Table extends JPanel implements Serializable {
colorize();
}
/**
* Call when closing to cleanup references and help GC.
*/
public void cleanup() {
data = null;
container = null;
axisParent = null;
centerPanel = null;
}
public int getUserLevel() {
return userLevel;
}

View File

@ -60,4 +60,7 @@ public class RomTree extends JTree implements MouseListener {
public void mouseEntered(MouseEvent e) { }
public void mouseExited(MouseEvent e) { }
public void cleanup() {
clearToggledPaths();
}
}

View File

@ -75,20 +75,4 @@ public class RomTreeNode extends DefaultMutableTreeNode {
this.rom = rom;
}
public void cleanup() {
try {
if (rom != null) {
rom.cleanup();
rom = null;
}
removeAllChildren();
removeFromParent();
userObject = null;
children.clear();
children = null;
}
catch (Throwable t) {
t.printStackTrace();
}
}
}