Ignore:
Timestamp:
2024-03-08T10:58:03+01:00 (2 months ago)
Author:
GerdP
Message:

fix #23527: Memory leak in relation editor

  • add new method wouldRelationBeUseful() in IRelationEditorActionAccess which doesn't call the problematic method getChangedRelation() to evaluate whether a relation would be useful if saved.
  • add comments and code in unit test for the method that shows how to handle the result of getChangedRelation() in case it is not needed any longer to avoid the memory leak.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/IRelationEditorActionAccess.java

    r18584 r19014  
    7272    /**
    7373     * Get the changed relation
    74      * @return The changed relation (note: will not be part of a dataset). This should never be {@code null}.
     74     * @return The changed relation (note: will not be part of a dataset) or the
     75     * value returned by {@code getEditor().getRelation()}. This should never be {@code null}.
     76     * If called for a temporary use of the relation instance, make sure to cleanup a copy to avoid memory leaks, see #23527
    7577     * @since 18413
    7678     */
     
    98100
    99101    /**
     102     * Check if the changed relation would be useful.
     103     * @return true if the saved relation has at least one tag and one member
     104     * @since 19014
     105     */
     106    default boolean wouldRelationBeUseful() {
     107        return (getTagModel().getRowCount() > 0 && getMemberTableModel().getRowCount() > 0);
     108    }
     109
     110    /**
    100111     * Get the text field that is used to edit the role.
    101112     * @return The role text field.
Note: See TracChangeset for help on using the changeset viewer.