Changeset 17205 in josm for trunk


Ignore:
Timestamp:
2020-10-15T15:17:57+02:00 (4 years ago)
Author:
GerdP
Message:

see #19885: memory leak with "temporary" objects in validator and actions
Start to use ChangeMembersCommand instead of ChangeCommand in those places where the cloned relation was only created for the ChangeCommand and not referenced elsewhere.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r17188 r17205  
    2323import org.openstreetmap.josm.command.AddCommand;
    2424import org.openstreetmap.josm.command.ChangeCommand;
     25import org.openstreetmap.josm.command.ChangeMembersCommand;
    2526import org.openstreetmap.josm.command.ChangeNodesCommand;
    2627import org.openstreetmap.josm.command.Command;
     
    298299     * @param cmds List of commands that will contain the new "add node" command
    299300     * @param newNodes List of nodes that will contain the new node
    300      * @return new way The modified way. Change command must be handled by the caller
     301     * @return The modified list of way nodes. Change command must be handled by the caller
    301302     */
    302303    private static List<Node> modifyWay(Node originalNode, Way w, List<Command> cmds, List<Node> newNodes) {
     
    332333                continue;
    333334            }
    334             Relation newRel = new Relation(r);
     335            List<RelationMember> newMembers = new ArrayList<>(r.getMembers());
    335336            // loop backwards because we add or remove members, works also when nodes appear
    336337            // multiple times in the same relation
     
    341342                    continue;
    342343                for (Node n : newNodes) {
    343                     newRel.addMember(i + 1, new RelationMember(rm.getRole(), n));
     344                    newMembers.add(i + 1, new RelationMember(rm.getRole(), n));
    344345                }
    345346                if (ExistingBothNew.NEW == memberships) {
    346347                    // remove old member
    347                     newRel.removeMember(i);
     348                    newMembers.remove(i);
    348349                }
    349350                changed = true;
    350351            }
    351352            if (changed) {
    352                 cmds.add(new ChangeCommand(r, newRel));
     353                cmds.add(new ChangeMembersCommand(r, newMembers));
    353354            }
    354355        }
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r17138 r17205  
    2929import org.openstreetmap.josm.data.osm.PrimitiveData;
    3030import org.openstreetmap.josm.data.osm.Relation;
     31import org.openstreetmap.josm.data.osm.RelationMember;
    3132import org.openstreetmap.josm.data.osm.RelationToChildReference;
    3233import org.openstreetmap.josm.data.osm.Way;
     
    307308        if (!silent && !callback.checkAndConfirmOutlyingDelete(parents, null))
    308309            return null;
    309         return new DeleteCommand(parents.iterator().next().getDataSet(), parents);
     310        return new DeleteCommand(parents);
    310311    }
    311312
     
    457458                .collect(Collectors.toSet());
    458459        for (Relation cur : relationsToBeChanged) {
    459             Relation rel = new Relation(cur);
    460             rel.removeMembersFor(primitivesToDelete);
    461             cmds.add(new ChangeCommand(cur, rel));
     460            List<RelationMember> newMembers = cur.getMembers();
     461            cur.getMembersFor(primitivesToDelete).forEach(newMembers::remove);
     462            cmds.add(new ChangeMembersCommand(cur, newMembers));
    462463        }
    463464
     
    465466        //
    466467        if (!primitivesToDelete.isEmpty()) {
    467             cmds.add(new DeleteCommand(primitivesToDelete.iterator().next().getDataSet(), primitivesToDelete));
     468            cmds.add(new DeleteCommand(primitivesToDelete));
    468469        }
    469470
Note: See TracChangeset for help on using the changeset viewer.