Ignore:
Timestamp:
2020-11-25T11:45:20+01:00 (5 years 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.