Changeset 18948 in josm


Ignore:
Timestamp:
2024-01-21T08:34:04+01:00 (11 months ago)
Author:
GerdP
Message:

fix #23423 Memory leak: Markerlayer doesn't remove MouseListener

  • add removeMouseListener() call in destroy()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r18927 r18948  
    101101
    102102    private final ListenerList<IGeoImageLayer.ImageChangeListener> imageChangeListenerListenerList = ListenerList.create();
     103    private MarkerMouseAdapter mouseAdapter;
     104    private MapView mapView;
    103105
    104106    /**
     
    193195        data.forEach(Marker::destroy);
    194196        data.clear();
     197        if (mouseAdapter != null && mapView != null)
     198            mapView.removeMouseListener(mouseAdapter);
    195199        super.destroy();
    196200    }
     
    198202    @Override
    199203    public LayerPainter attachToMapView(MapViewEvent event) {
    200         event.getMapView().addMouseListener(new MarkerMouseAdapter());
     204        if (mapView != null) {
     205            Logging.warn("MarkerLayer was already attached to a MapView");
     206        }
     207        mapView = event.getMapView();
     208        mouseAdapter = new MarkerMouseAdapter();
     209        mapView.addMouseListener(mouseAdapter);
    201210
    202211        if (event.getMapView().playHeadMarker == null) {
Note: See TracChangeset for help on using the changeset viewer.