Changeset 17226 in josm


Ignore:
Timestamp:
2020-10-18T11:50:39+02:00 (2 days ago)
Author:
GerdP
Message:

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

  • initialize cloneMap as Collections.emptyMap() to reduce memory footprint for Commamds

The original code allocated a HashMap for all commands, only some require it. Typically, the map contains 0 or 1 entries, so use Utils.toUnmodifiable() to optimize further.

File:
1 edited

Legend:

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

    r17102 r17226  
    44import java.util.ArrayList;
    55import java.util.Collection;
    6 import java.util.HashMap;
     6import java.util.Collections;
    77import java.util.LinkedHashMap;
    88import java.util.Map;
     
    2020import org.openstreetmap.josm.data.osm.visitor.OsmPrimitiveVisitor;
    2121import org.openstreetmap.josm.tools.CheckParameterUtil;
     22import org.openstreetmap.josm.tools.Utils;
    2223
    2324/**
     
    123124
    124125    /** the map of OsmPrimitives in the original state to OsmPrimitives in cloned state */
    125     private Map<OsmPrimitive, PrimitiveData> cloneMap = new HashMap<>();
     126    private Map<OsmPrimitive, PrimitiveData> cloneMap = Collections.emptyMap();
    126127
    127128    /** the dataset which this command is applied to */
     
    154155            osm.accept(visitor);
    155156        }
    156         cloneMap = visitor.orig;
     157        cloneMap = Utils.toUnmodifiableMap(visitor.orig);
    157158        return true;
    158159    }
Note: See TracChangeset for help on using the changeset viewer.