Changeset 17357 in josm


Ignore:
Timestamp:
2020-11-25T11:45:20+01:00 (5 months ago)
Author:
GerdP
Message:

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

  • add hint regarding memory leak in javadoc to copy constructors for Way and Relation
  • decrease memory footprint of incomplete ways
Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r16553 r17357  
    194194
    195195    /**
    196      * Constructs an identical clone of the argument.
     196     * Constructs an identical clone of the argument and links members to it.
     197     * See #19885 for possible memory leaks.
    197198     * @param clone The relation to clone
    198199     * @param clearMetadata If {@code true}, clears the OSM id and other metadata as defined by {@link #clearOsmMetadata}.
     
    210211
    211212    /**
    212      * Constructs an identical clone of the argument.
     213     * Constructs an identical clone of the argument and links members to it.
     214     * See #19885 for possible memory leaks.
    213215     * @param clone The relation to clone
    214216     * @param clearMetadata If {@code true}, clears the OSM id and other metadata as defined by {@link #clearOsmMetadata}.
     
    220222
    221223    /**
    222      * Create an identical clone of the argument (including the id)
     224     * Create an identical clone of the argument (including the id) and links members to it.
     225     * See #19885 for possible memory leaks.
    223226     * @param clone The relation to clone, including its id
    224227     */
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r17103 r17357  
    3131
    3232    static final UniqueIdGenerator idGenerator = new UniqueIdGenerator();
     33    private static final Node[] EMPTY_NODES = new Node[0];
    3334
    3435    /**
    3536     * All way nodes in this way
    3637     */
    37     private Node[] nodes = new Node[0];
     38    private Node[] nodes = EMPTY_NODES;
    3839    private BBox bbox;
    3940
     
    5354            }
    5455
    55             if (nodes == null) {
    56                 this.nodes = new Node[0];
     56            if (nodes == null || nodes.isEmpty()) {
     57                this.nodes = EMPTY_NODES;
    5758            } else {
    58                 this.nodes = nodes.toArray(new Node[0]);
     59                this.nodes = nodes.toArray(EMPTY_NODES);
    5960            }
    6061            for (Node node: this.nodes) {
     
    196197    /**
    197198     * Constructs a new {@code Way} from an existing {@code Way}.
     199     * This  adds links from all way nodes to the clone. See #19885 for possible memory leaks.
    198200     * @param original The original {@code Way} to be identically cloned. Must not be null
    199201     * @param clearMetadata If {@code true}, clears the OSM id and other metadata as defined by {@link #clearOsmMetadata}.
     
    212214    /**
    213215     * Constructs a new {@code Way} from an existing {@code Way}.
     216     * This  adds links from all way nodes to the clone. See #19885 for possible memory leaks.
    214217     * @param original The original {@code Way} to be identically cloned. Must not be null
    215218     * @param clearMetadata If {@code true}, clears the OSM id and other metadata as defined by {@link #clearOsmMetadata}.
     
    223226    /**
    224227     * Constructs a new {@code Way} from an existing {@code Way} (including its id).
     228     * This  adds links from all way nodes to the clone. See #19885 for possible memory leaks.
    225229     * @param original The original {@code Way} to be identically cloned. Must not be null
    226230     * @since 86
Note: See TracChangeset for help on using the changeset viewer.