Changeset 28599 in osm for applications/editors/josm


Ignore:
Timestamp:
2012-08-22T23:50:49+02:00 (13 years ago)
Author:
donvip
Message:

[josm_tag2link] See #josm7980 - Fix memory leak

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified applications/editors/josm/plugins/tag2link/src/org/openstreetmap/josm/plugins/tag2link/Tag2LinkPlugin.java

    r28547 r28599  
    4444    // private Tag2LinkPreferenceSetting preferenceSetting; TODO
    4545
     46    private SelectionPopupListener selectionPopupListener;
     47    private MembershipPopupListener membershipPopupListener;
     48    private PropertyPopupListener propertyPopupListener;
     49    private RelationPopupListener relationPopupListener;
     50   
    4651    /**
    4752     * Initializes the plugin.
     
    6974        if (newFrame != null) {
    7075            // Initialize dialogs listeners only after the main frame is created
    71             newFrame.selectionListDialog.addPopupMenuListener(new SelectionPopupListener(newFrame));
    72             newFrame.propertiesDialog.addMembershipPopupMenuListener(new MembershipPopupListener(newFrame));
    73             newFrame.propertiesDialog.addPropertyPopupMenuListener(new PropertyPopupListener(newFrame));
    74             newFrame.relationListDialog.addPopupMenuListener(new RelationPopupListener(newFrame));
     76            newFrame.selectionListDialog.addPopupMenuListener(selectionPopupListener = new SelectionPopupListener(newFrame));
     77            newFrame.propertiesDialog.addMembershipPopupMenuListener(membershipPopupListener = new MembershipPopupListener(newFrame));
     78            newFrame.propertiesDialog.addPropertyPopupMenuListener(propertyPopupListener = new PropertyPopupListener(newFrame));
     79            newFrame.relationListDialog.addPopupMenuListener(relationPopupListener = new RelationPopupListener(newFrame));
     80        } else if (oldFrame != null) {
     81            // Remove listeners from previous frame to avoid memory leaks
     82            if (oldFrame.selectionListDialog != null) {
     83                oldFrame.selectionListDialog.removePopupMenuListener(selectionPopupListener);
     84            }
     85            if (oldFrame.propertiesDialog != null) {
     86                oldFrame.propertiesDialog.removeMembershipPopupMenuListener(membershipPopupListener);
     87                oldFrame.propertiesDialog.removePropertyPopupMenuListener(propertyPopupListener);
     88            }
     89            if (oldFrame.relationListDialog != null) {
     90                oldFrame.relationListDialog.removePopupMenuListener(relationPopupListener);
     91            }
     92            selectionPopupListener = null;
     93            membershipPopupListener = null;
     94            propertyPopupListener = null;
     95            relationPopupListener = null;
    7596        }
    7697    }
Note: See TracChangeset for help on using the changeset viewer.