Ignore:
Timestamp:
2020-12-07T18:17:10+01:00 (4 years ago)
Author:
GerdP
Message:

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

  • simplify code, use ChangeMembersCommand instead of ChangeCommand
Location:
applications/editors/josm/plugins/buildings_tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/buildings_tools/build.xml

    r35171 r35668  
    44    <property name="commit.message" value="buildings_tools: add option to disable click+drag"/>
    55    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    6     <property name="plugin.main.version" value="14960"/>
     6    <property name="plugin.main.version" value="17329"/>
    77   
    88    <!-- Configure these properties (replace "..." accordingly).
  • applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/Building.java

    r35574 r35668  
    2222import org.openstreetmap.josm.actions.CreateCircleAction;
    2323import org.openstreetmap.josm.command.AddCommand;
    24 import org.openstreetmap.josm.command.ChangeCommand;
     24import org.openstreetmap.josm.command.ChangeMembersCommand;
    2525import org.openstreetmap.josm.command.ChangeNodesCommand;
    2626import org.openstreetmap.josm.command.Command;
     
    472472                for (OsmPrimitive p : addrNode.getReferrers()) {
    473473                    Relation r = (Relation) p;
    474                     Relation rnew = new Relation(r);
    475                     for (int i = 0; i < r.getMembersCount(); i++) {
    476                         RelationMember member = r.getMember(i);
     474                    List<RelationMember> members = new ArrayList<>(r.getMembers());
     475                    for (int i = 0; i < members.size(); i++) {
     476                        RelationMember member = members.get(i);
    477477                        if (addrNode.equals(member.getMember())) {
    478                             rnew.removeMember(i);
    479                             rnew.addMember(i, new RelationMember(member.getRole(), w));
     478                            members.set(i, new RelationMember(member.getRole(), w));
    480479                        }
    481480                    }
    482                     addressCmds.add(new ChangeCommand(r, rnew));
     481                    addressCmds.add(new ChangeMembersCommand(r, members));
    483482                }
    484483                addressCmds.add(new DeleteCommand(addrNode));
  • applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/MergeAddrPointsAction.java

    r35579 r35668  
    1616import java.util.Map;
    1717import java.util.Map.Entry;
     18import java.util.Set;
    1819import java.util.stream.Collectors;
    19 import java.util.Set;
    2020
    2121import javax.swing.JOptionPane;
    2222
    2323import org.openstreetmap.josm.actions.JosmAction;
    24 import org.openstreetmap.josm.command.ChangeCommand;
     24import org.openstreetmap.josm.command.ChangeMembersCommand;
    2525import org.openstreetmap.josm.command.ChangePropertyCommand;
    2626import org.openstreetmap.josm.command.Command;
     
    158158
    159159        for (Relation r : modifiedRelations) {
    160             Relation rnew = new Relation(r);
     160            List<RelationMember> members = new ArrayList<>(r.getMembers());
    161161            boolean modified = false;
    162162            for (Pair<Node, Way> repl : replaced) {
    163                 for (int i = 0; i < rnew.getMembersCount(); i++) {
    164                     RelationMember member = rnew.getMember(i);
     163                for (int i = 0; i < members.size(); i++) {
     164                    RelationMember member = members.get(i);
    165165                    if (repl.a.equals(member.getMember())) {
    166                         rnew.removeMember(i);
    167                         rnew.addMember(i, new RelationMember(member.getRole(), repl.b));
     166                        members.set(i, new RelationMember(member.getRole(), repl.b));
    168167                        modified = true;
    169168                    }
     
    171170            }
    172171            if (modified) {
    173                 cmds.add(new ChangeCommand(r, rnew));
     172                cmds.add(new ChangeMembersCommand(r, members));
    174173            }
    175174        }
Note: See TracChangeset for help on using the changeset viewer.