Changeset 17187 in josm for trunk/src


Ignore:
Timestamp:
2020-10-13T17:56:43+02:00 (4 years ago)
Author:
GerdP
Message:

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

  • let modifyWay() return the list of nodes instead of a newly created copy of the way

Simplifies code and avoids another memory leak

File:
1 edited

Legend:

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

    r16553 r17187  
    188188        List<Command> cmds = new ArrayList<>();
    189189        List<Node> newNodes = new ArrayList<>();
    190         Way modWay = modifyWay(selectedNode, way, cmds, newNodes);
    191         cmds.add(new ChangeNodesCommand(way, modWay.getNodes()));
     190        cmds.add(new ChangeNodesCommand(way, modifyWay(selectedNode, way, cmds, newNodes)));
    192191        if (dialog != null) {
    193192            update(dialog, selectedNode, newNodes, cmds);
     
    301300     * @return new way The modified way. Change command must be handled by the caller
    302301     */
    303     private static Way modifyWay(Node originalNode, Way w, List<Command> cmds, List<Node> newNodes) {
     302    private static List<Node> modifyWay(Node originalNode, Way w, List<Command> cmds, List<Node> newNodes) {
    304303        // clone the node for the way
    305304        Node newNode = cloneNode(originalNode, cmds);
     
    308307        List<Node> nn = new ArrayList<>(w.getNodes());
    309308        nn.replaceAll(n -> n == originalNode ? newNode : n);
    310         Way newWay = new Way(w);
    311         newWay.setNodes(nn);
    312 
    313         return newWay;
     309        return nn;
    314310    }
    315311
     
    393389            if (w.isFirstLastNode(selectedNode))
    394390                warnParents.add(w);
    395             cmds.add(new ChangeNodesCommand(w, modifyWay(selectedNode, w, cmds, newNodes).getNodes()));
     391            cmds.add(new ChangeNodesCommand(w, modifyWay(selectedNode, w, cmds, newNodes)));
    396392        }
    397393
Note: See TracChangeset for help on using the changeset viewer.