Ignore:
Timestamp:
2024-03-08T10:58:03+01:00 (2 months ago)
Author:
GerdP
Message:

fix #23527: Memory leak in relation editor

  • add new method wouldRelationBeUseful() in IRelationEditorActionAccess which doesn't call the problematic method getChangedRelation() to evaluate whether a relation would be useful if saved.
  • add comments and code in unit test for the method that shows how to handle the result of getChangedRelation() in case it is not needed any longer to avoid the memory leak.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java

    r18968 r19014  
    5656import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
    5757import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    58 import org.openstreetmap.josm.data.osm.IRelation;
    5958import org.openstreetmap.josm.data.osm.OsmPrimitive;
    6059import org.openstreetmap.josm.data.osm.Relation;
     
    406405     * builds the panel with the OK and the Cancel button
    407406     * @param okAction OK action
     407     * @param deleteAction  Delete action
    408408     * @param cancelAction Cancel action
    409409     *
     
    422422        // Keep users from saving invalid relations -- a relation MUST have at least a tag with the key "type"
    423423        // AND must contain at least one other OSM object.
    424         final TableModelListener listener = l -> updateOkPanel(this.actionAccess.getChangedRelation(), okButton, deleteButton);
     424        final TableModelListener listener = l -> updateOkPanel(okButton, deleteButton);
    425425        listener.tableChanged(null);
    426426        this.memberTableModel.addTableModelListener(listener);
     
    430430
    431431    /**
    432      * Update the OK panel area
    433      * @param newRelation What the new relation would "look" like if it were to be saved now
     432     * Update the OK panel area with a temporary relation that looks if it were to be saved now.
    434433     * @param okButton The OK button
    435434     * @param deleteButton The delete button
    436435     */
    437     private void updateOkPanel(IRelation<?> newRelation, JButton okButton, JButton deleteButton) {
    438         okButton.setVisible(newRelation.isUseful() || this.getRelationSnapshot() == null);
    439         deleteButton.setVisible(!newRelation.isUseful() && this.getRelationSnapshot() != null);
    440         if (this.getRelationSnapshot() == null && !newRelation.isUseful()) {
     436    private void updateOkPanel(JButton okButton, JButton deleteButton) {
     437        boolean useful = this.actionAccess.wouldRelationBeUseful();
     438        okButton.setVisible(useful || this.getRelationSnapshot() == null);
     439        deleteButton.setVisible(!useful && this.getRelationSnapshot() != null);
     440        if (this.getRelationSnapshot() == null && !useful) {
    441441            okButton.setText(tr("Delete"));
    442442        } else {
Note: See TracChangeset for help on using the changeset viewer.