Ignore:
Timestamp:
2020-11-25T11:50:22+01:00 (3 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/actions/ReverseWayAction.java

    r17333 r17358  
    1818import org.openstreetmap.josm.actions.corrector.ReverseWayNoTagCorrector;
    1919import org.openstreetmap.josm.actions.corrector.ReverseWayTagCorrector;
    20 import org.openstreetmap.josm.command.ChangeCommand;
     20import org.openstreetmap.josm.command.ChangeNodesCommand;
    2121import org.openstreetmap.josm.command.Command;
    2222import org.openstreetmap.josm.command.SequenceCommand;
     
    4141     */
    4242    public static class ReverseWayResult {
    43         private final Way newWay;
    4443        private final Collection<Command> tagCorrectionCommands;
    4544        private final Command reverseCommand;
     
    4746        /**
    4847         * Create a new {@link ReverseWayResult}
    49          * @param newWay The new way primitive
    5048         * @param tagCorrectionCommands The commands to correct the tags
    5149         * @param reverseCommand The command to reverse the way
    5250         */
    53         public ReverseWayResult(Way newWay, Collection<Command> tagCorrectionCommands, Command reverseCommand) {
    54             this.newWay = newWay;
     51        public ReverseWayResult(Collection<Command> tagCorrectionCommands, Command reverseCommand) {
    5552            this.tagCorrectionCommands = tagCorrectionCommands;
    5653            this.reverseCommand = reverseCommand;
    57         }
    58 
    59         /**
    60          * Gets the new way object
    61          * @return The new, reversed way
    62          */
    63         public Way getNewWay() {
    64             return newWay;
    6554        }
    6655
     
    150139    public static ReverseWayResult reverseWay(Way w) throws UserCancelException {
    151140        ReverseWayNoTagCorrector.checkAndConfirmReverseWay(w);
    152         Way wnew = new Way(w);
    153         List<Node> nodesCopy = wnew.getNodes();
     141        List<Node> nodesCopy = w.getNodes();
    154142        Collections.reverse(nodesCopy);
    155         wnew.setNodes(nodesCopy);
    156143
    157144        Collection<Command> corrCmds = Collections.<Command>emptyList();
    158145        if (Config.getPref().getBoolean("tag-correction.reverse-way", true)) {
    159             corrCmds = new ReverseWayTagCorrector().execute(w, wnew);
     146            corrCmds = new ReverseWayTagCorrector().execute(w, w);
    160147        }
    161         return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w, wnew));
     148        return new ReverseWayResult(corrCmds, new ChangeNodesCommand(w, new ArrayList<>(nodesCopy)));
    162149    }
    163150
Note: See TracChangeset for help on using the changeset viewer.