Changeset 17047 in josm


Ignore:
Timestamp:
2020-09-20T10:43:08+02:00 (7 months ago)
Author:
GerdP
Message:

fix #19789: memory leak with gpx waypoints

  • implement destroy in class Marker and call it for each object in a destroyed MarkerLayer
  • handle also AbstractModifiableLayer in AutosaveTask
Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
3 edited

Legend:

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

    r16643 r17047  
    316316                noteLayer.getNoteData().removeNoteDataUpdateListener(this);
    317317                cleanupLayer(noteLayer);
     318            }
     319        } else if (e.getRemovedLayer() instanceof AbstractModifiableLayer) {
     320            synchronized (layersLock) {
     321                cleanupLayer((AbstractModifiableLayer) e.getRemovedLayer());
    318322            }
    319323        }
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r16879 r17047  
    3232import org.openstreetmap.josm.gui.layer.GpxLayer;
    3333import org.openstreetmap.josm.gui.preferences.display.GPXSettingsPanel;
     34import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
     35import org.openstreetmap.josm.tools.Destroyable;
    3436import org.openstreetmap.josm.tools.ImageProvider;
    3537import org.openstreetmap.josm.tools.Logging;
     
    7476 * @author Frederik Ramm
    7577 */
    76 public class Marker implements TemplateEngineDataProvider, ILatLon {
     78public class Marker implements TemplateEngineDataProvider, ILatLon, Destroyable {
    7779
    7880    /**
     
    148150
    149151    private CachedLatLon coor;
     152    private PreferenceChangedListener listener = l -> updateText();
    150153
    151154    private boolean erroneous;
     
    175178        this.text = text;
    176179
    177         Preferences.main().addKeyPreferenceChangeListener("draw.rawgps." + getTextTemplateKey(), l -> updateText());
     180        Preferences.main().addKeyPreferenceChangeListener(getPreferenceKey(), listener);
    178181    }
    179182
     
    370373        cachedText = null;
    371374        cachedDefaultTemplate = null;
    372         cachedTemplates = new HashMap<>();
     375        cachedTemplates.clear();
    373376    }
    374377
     
    433436        }
    434437    }
     438
     439    @Override
     440    public void destroy() {
     441        cachedTemplates.clear();
     442        Preferences.main().removeKeyPreferenceChangeListener(getPreferenceKey(), listener);
     443    }
     444
     445    private String getPreferenceKey() {
     446        return "draw.rawgps." + getTextTemplateKey();
     447    }
    435448}
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r16967 r17047  
    172172        currentMarker = null;
    173173        fromLayer = null;
     174        data.forEach(Marker::destroy);
    174175        data.clear();
    175176        super.destroy();
Note: See TracChangeset for help on using the changeset viewer.