Skip to content

Commit

Permalink
Free Memory On File Container Removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Konloch committed Jan 16, 2024
1 parent a1d9c15 commit aea66fe
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public Delete()
@Override
public void actionPerformed(ActionEvent e)
{
BytecodeViewer.viewer.resourcePane.removeNode(tree, selPath);
//remove memory reference
BytecodeViewer.viewer.resourcePane.deletePath(selPath);

//remove gui reference
BytecodeViewer.viewer.resourcePane.removeNode(tree, selPath);
}
})));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ private void showContextMenu(ResourceTree tree, TreePath selPath, int x, int y)
rightClickMenu.show(this.tree, x, y);
}

//used to remove resources from the resource list
public void removeFile(ResourceContainer resourceContainer)
{
while (BytecodeViewer.resourceContainers.values().remove(resourceContainer));
LazyNameUtil.removeName(resourceContainer.name);
}

public ResourceListPane()
{
super("Files", TranslatedComponents.FILES);
Expand Down Expand Up @@ -260,8 +253,10 @@ public void expandAll(final JTree tree, final TreePath parent,
}
}

public void removeNode(final JTree tree, final TreePath nodePath) {
public void removeNode(final JTree tree, final TreePath nodePath)
{
MutableTreeNode node = findNodeByPath(nodePath);

if (node == null)
return;

Expand Down Expand Up @@ -326,6 +321,7 @@ public void quickDecompile(Decompiler decompiler, TreePath selPath, boolean quic

public void openPath(TreePath path)
{
//do not open null path, or gui root path
if (path == null || path.getPathCount() == 1)
return;

Expand All @@ -337,15 +333,8 @@ public void openPath(TreePath path)
nameBuffer.append("/");
}

String cheapHax = path.getPathComponent(1).toString();
ResourceContainer container = null;

for (ResourceContainer c : BytecodeViewer.resourceContainers.values())
{
if (c.name.equals(cheapHax))
container = c;
}

String pathName = path.getPathComponent(1).toString();
ResourceContainer container = getContainerFromName(pathName);
String name = nameBuffer.toString();

boolean resourceMode = false;
Expand Down Expand Up @@ -417,6 +406,48 @@ else if(container.resourceFiles.containsKey(name))
}
}
}

//TODO support non-containers being removed
// this will require us finding all child nodes in the tree path provided,
// then removing each one by one from both memory and the GUI
public void deletePath(TreePath path)
{
//do not open null path, or gui root path
if (path == null || path.getPathCount() == 1)
return;

//verify the path is a container root
if(path.getPathCount() != 2)
return;

String pathName = path.getPathComponent(1).toString();
ResourceContainer container = getContainerFromName(pathName);

if(container != null)
{
deleteContainer(container);
}
}

public void deleteContainer(ResourceContainer container)
{
container.resourceFiles.clear();
container.resourceClasses.clear();
container.resourceClassBytes.clear();
BytecodeViewer.resourceContainers.values().remove(container);
LazyNameUtil.removeName(container.name);
}

public ResourceContainer getContainerFromName(String name)
{
for (ResourceContainer c : BytecodeViewer.resourceContainers.values())
{
if (c.name.equals(name))
return c;
}

return null;
}

public void attachTreeListeners()
{
Expand Down

0 comments on commit aea66fe

Please sign in to comment.