Changeset 17367 in josm for trunk/src/org


Ignore:
Timestamp:
2020-11-27T15:37:14+01:00 (3 years ago)
Author:
GerdP
Message:

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

  • simplify code in SplitWayCommand, no need to create a way when we only need to know the nodes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/SplitWayCommand.java

    r17365 r17367  
    436436
    437437        // Change the original way
    438         final Way changedWay = new Way(way);
    439         changedWay.setNodes(wayToKeep.getNodes());
    440         commandList.add(new ChangeNodesCommand(way, changedWay.getNodes()));
     438        final List<Node> changedWayNodes = wayToKeep.getNodes();
     439        commandList.add(new ChangeNodesCommand(way, changedWayNodes));
    441440        for (Way wayToAdd : newWays) {
    442441            commandList.add(new AddCommand(way.getDataSet(), wayToAdd));
     
    465464                    boolean insert = true;
    466465                    if (relationSpecialTypes.containsKey(type) && "restriction".equals(relationSpecialTypes.get(type))) {
    467                         RelationInformation rValue = treatAsRestriction(r, rm, c, newWays, way, changedWay);
     466                        RelationInformation rValue = treatAsRestriction(r, rm, c, newWays, way, changedWayNodes);
    468467                        if (rValue.warnme) warnings.add(WarningType.GENERIC);
    469468                        insert = rValue.insert;
     
    570569            }
    571570        }
    572         changedWay.setNodes(null); // see #19885
    573571        return new Analysis(relationAnalyses, commandList, warnings, numberOfRelations);
    574572    }
     
    785783    private static RelationInformation treatAsRestriction(Relation r,
    786784            RelationMember rm, Relation c, Collection<Way> newWays, Way way,
    787             Way changedWay) {
     785            List<Node> changedWayNodes) {
    788786        RelationInformation relationInformation = new RelationInformation();
    789787        /* this code assumes the restriction is correct. No real error checking done */
     
    802800            Way res = null;
    803801            for (Node n : nodes) {
    804                 if (changedWay.isFirstLastNode(n)) {
     802                if (changedWayNodes.get(0) == n || changedWayNodes.get(changedWayNodes.size() - 1) == n) {
    805803                    res = way;
    806804                }
Note: See TracChangeset for help on using the changeset viewer.