Skip to content

Commit

Permalink
fix #23423 Memory leak: Markerlayer doesn't remove MouseListener
Browse files Browse the repository at this point in the history
- add removeMouseListener() call in destroy()

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18948 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
GerdP authored and GerdP committed Jan 21, 2024
1 parent 6f44d22 commit a3eba43
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public class MarkerLayer extends Layer implements JumpToMarkerLayer, IGeoImageLa
final BasicStroke markerStroke = new StrokeProperty("draw.rawgps.markers.stroke", "1").get();

private final ListenerList<IGeoImageLayer.ImageChangeListener> imageChangeListenerListenerList = ListenerList.create();
private MarkerMouseAdapter mouseAdapter;
private MapView mapView;

/**
* The default color that is used for drawing markers.
Expand Down Expand Up @@ -192,12 +194,19 @@ public synchronized void destroy() {
fromLayer = null;
data.forEach(Marker::destroy);
data.clear();
if (mouseAdapter != null && mapView != null)
mapView.removeMouseListener(mouseAdapter);
super.destroy();
}

@Override
public LayerPainter attachToMapView(MapViewEvent event) {
event.getMapView().addMouseListener(new MarkerMouseAdapter());
if (mapView != null) {
Logging.warn("MarkerLayer was already attached to a MapView");
}
mapView = event.getMapView();
mouseAdapter = new MarkerMouseAdapter();
mapView.addMouseListener(mouseAdapter);

if (event.getMapView().playHeadMarker == null) {
event.getMapView().playHeadMarker = PlayHeadMarker.create();
Expand Down

0 comments on commit a3eba43

Please sign in to comment.