Ignore:
Timestamp:
2020-11-25T11:50:22+01:00 (4 years ago)
Author:
GerdP
Message:

see #19885: memory leak with "temporary" objects in validator and actions

  • (hopefully) fix memory leaks in complex actions
  • handle complex cases with presets and RelationEditor

I hope these changes don't break plugins which extend or overwrite RelationEditor

File:
1 edited

Legend:

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

    r17172 r17358  
    55
    66import java.awt.Component;
     7import java.util.ArrayList;
     8import java.util.List;
    79
    810import javax.swing.JOptionPane;
     
    1113import org.openstreetmap.josm.command.AddCommand;
    1214import org.openstreetmap.josm.command.ChangeCommand;
     15import org.openstreetmap.josm.command.ChangeMembersCommand;
     16import org.openstreetmap.josm.command.ChangePropertyCommand;
     17import org.openstreetmap.josm.command.Command;
    1318import org.openstreetmap.josm.command.conflict.ConflictAddCommand;
    1419import org.openstreetmap.josm.data.UndoRedoHandler;
     
    8691        tagEditorModel.applyToPrimitive(editedRelation);
    8792        getMemberTableModel().applyToRelation(editedRelation);
    88         if (!editedRelation.hasEqualSemanticAttributes(originRelation, false)) {
     93        List<Command> cmds = new ArrayList<>();
     94        if (originRelation.getKeys().equals(editedRelation.getKeys())) {
     95            cmds.add(new ChangeMembersCommand(originRelation, editedRelation.getMembers()));
     96        }
     97        Command cmdProps = ChangePropertyCommand.build(originRelation, editedRelation);
     98        if (cmdProps != null)
     99            cmds.add(cmdProps);
     100        if (cmds.size() >= 2) {
    89101            UndoRedoHandler.getInstance().add(new ChangeCommand(originRelation, editedRelation));
    90         } else {
     102        } else if (!cmds.isEmpty()) {
     103            UndoRedoHandler.getInstance().add(cmds.get(0));
    91104            editedRelation.setMembers(null); // see #19885
    92105        }
Note: See TracChangeset for help on using the changeset viewer.