Skip to content

Commit

Permalink
fix memory leak, ImgDisplay.destroy() was only called when at least…
Browse files Browse the repository at this point in the history
… one image was viewed

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18947 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
GerdP authored and GerdP committed Jan 19, 2024
1 parent cfb5245 commit 6f44d22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public class ImageDisplay extends JComponent implements Destroyable, PreferenceC

private UpdateImageThread updateImageThreadInstance;

private boolean destroyed;

private class UpdateImageThread extends Thread {
private boolean restart;

Expand Down Expand Up @@ -619,13 +621,16 @@ public ImageDisplay(ImageProcessor imageProcessor) {

@Override
public void destroy() {
removeMouseListener(imgMouseListener);
removeMouseWheelListener(imgMouseListener);
removeMouseMotionListener(imgMouseListener);
Config.getPref().removePreferenceChangeListener(this);
if (imageProcessor instanceof ImageryFilterSettings) {
((ImageryFilterSettings) imageProcessor).removeFilterChangeListener(this);
if (!destroyed) {
removeMouseListener(imgMouseListener);
removeMouseWheelListener(imgMouseListener);
removeMouseMotionListener(imgMouseListener);
Config.getPref().removePreferenceChangeListener(this);
if (imageProcessor instanceof ImageryFilterSettings) {
((ImageryFilterSettings) imageProcessor).removeFilterChangeListener(this);
}
}
destroyed = true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ public void destroy() {
toggleAction.destroy();
cancelLoadingImage();
super.destroy();
// make sure that Image Display is destroyed here, it might not be a component
imgDisplay.destroy();
// Ensure that this dialog is removed from memory
destroyInstance();
}
Expand Down

0 comments on commit 6f44d22

Please sign in to comment.