Changeset 17440 in josm


Ignore:
Timestamp:
2021-01-04T17:06:18+01:00 (4 years ago)
Author:
GerdP
Message:

see #17184: Memory leaks

  • remove more listeners in destroy()
  • reset fields which might reference OSM objects
  • call data.clearSelection when data layer is destroyed so that fewer actions keep references on OSM elements in that layer

My goal here: When a layer is closed JOSM should really allow to GC all OSM data and GPX data that was loaded before.

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java

    r17141 r17440  
    191191        map.keyDetector.removeModifierExListener(this);
    192192        temporaryLayer.invalidate();
     193        targetWay = null;
     194        candidateNode = null;
     195        candidateSegment = null;
    193196    }
    194197
  • trunk/src/org/openstreetmap/josm/gui/dialogs/DeleteFromRelationConfirmationDialog.java

    r16438 r17440  
    169169            ).applySafe(this);
    170170            setCanceled(false);
    171         } else if (isShowing()) { // Avoid IllegalComponentStateException like in #8775
    172             new WindowGeometry(this).remember(getClass().getName() + ".geometry");
     171        } else {
     172            if (isShowing()) { // Avoid IllegalComponentStateException like in #8775
     173                new WindowGeometry(this).remember(getClass().getName() + ".geometry");
     174            }
     175            model.data.clear();
    173176        }
    174177        super.setVisible(visible);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r17418 r17440  
    175175    private final transient MainLayerManager layerManager;
    176176
     177    private PopupMenuHandler popupHandler;
     178
     179    private LayerListModelListener modelListener;
     180
    177181    /**
    178182     * registers (shortcut to toggle right hand side toggle dialogs)+(number keys) shortcuts
     
    212216        TableHelper.setFont(layerList, getClass());
    213217        layerList.setSelectionModel(selectionModel);
    214         layerList.addMouseListener(new PopupMenuHandler());
     218        popupHandler = new PopupMenuHandler();
     219        layerList.addMouseListener(popupHandler);
    215220        layerList.setBackground(UIManager.getColor("Button.background"));
    216221        layerList.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
     
    274279        model.populate();
    275280        model.setSelectedLayer(layerManager.getActiveLayer());
    276         model.addLayerListModelListener(
    277                 new LayerListModelListener() {
    278                     @Override
    279                     public void makeVisible(int row, Layer layer) {
    280                         layerList.scrollToVisible(row, 0);
    281                         layerList.repaint();
    282                     }
    283 
    284                     @Override
    285                     public void refresh() {
    286                         layerList.repaint();
    287                     }
    288                 }
    289                 );
     281        modelListener = new LayerListModelListener() {
     282            @Override
     283            public void makeVisible(int row, Layer layer) {
     284                layerList.scrollToVisible(row, 0);
     285                layerList.repaint();
     286            }
     287
     288            @Override
     289            public void refresh() {
     290                layerList.repaint();
     291            }
     292        };
     293
     294        model.addLayerListModelListener(modelListener);
    290295
    291296        // -- move up action
     
    398403        JumpToMarkerActions.unregisterActions();
    399404        layerList.setTransferHandler(null);
     405        layerList.removeMouseListener(popupHandler);
    400406        DISPLAY_NUMBERS.removeListener(visibilityWidthListener);
    401407        ExpertToggleAction.removeExpertModeChangeListener(visibilityWidthListener);
     
    403409        cycleLayerUpAction.destroy();
    404410        cycleLayerDownAction.destroy();
     411        model.removeLayerListModelListener(modelListener);
    405412        super.destroy();
    406413        instance = null;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r17358 r17440  
    248248    private final transient TaggingPresetHandler presetHandler = new TaggingPresetCommandHandler();
    249249
     250    private PopupMenuLauncher popupMenuLauncher;
     251
    250252    private static final BooleanProperty PROP_AUTORESIZE_TAGS_TABLE = new BooleanProperty("propertiesdialog.autoresizeTagsTable", false);
    251253
     
    419421        });
    420422
    421         membershipTable.addMouseListener(new PopupMenuLauncher(membershipMenu) {
     423        popupMenuLauncher = new PopupMenuLauncher(membershipMenu) {
    422424            @Override
    423425            protected int checkTableSelection(JTable table, Point p) {
     
    446448                highlightHelper.clear();
    447449            }
    448         });
     450        };
     451        membershipTable.addMouseListener(popupMenuLauncher);
    449452    }
    450453
     
    614617    public void destroy() {
    615618        destroyTaginfoNationalActions();
     619        membershipTable.removeMouseListener(popupMenuLauncher);
    616620        super.destroy();
    617621        Config.getPref().removeKeyPreferenceChangeListener("display.discardable-keys", preferenceListener);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java

    r17401 r17440  
    186186        if (editorAccess.getEditor() instanceof Component) {
    187187            ((Component) editorAccess.getEditor()).setVisible(false);
     188            editorAccess.getEditor().setRelation(null);
    188189        }
     190
    189191    }
    190192
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r17399 r17440  
    11191119        data.removeDataSetListener(dataSetListenerAdapter);
    11201120        data.removeDataSetListener(MultipolygonCache.getInstance());
     1121        data.clearSelection();
     1122        validationErrors.clear();
    11211123        removeClipboardDataFor(this);
    11221124        recentRelations.clear();
Note: See TracChangeset for help on using the changeset viewer.