Changeset 14500 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2018-12-03T01:53:41+01:00 (6 years ago)
Author:
Don-vip
Message:

see #17040 - fix memory leak after primitives are copied to clipboard

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/ClipboardUtils.java

    r13647 r14500  
    166166        }
    167167    }
     168
     169    /**
     170     * Clears the system clipboard.
     171     * @return True if the clear was successful
     172     * @since 14500
     173     */
     174    public static boolean clear() {
     175        // Cannot simply set clipboard contents to null, see https://stackoverflow.com/a/18254949/2257172
     176        return copy(new StringSelection(""));
     177    }
    168178}
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandler.java

    r12642 r14500  
    2424
    2525/**
    26  * This transfer hanlder provides the ability to transfer OSM data. It allows you to receive files, primitives or tags.
     26 * This transfer handler provides the ability to transfer OSM data. It allows you to receive files, primitives or tags.
    2727 * @author Michael Zangl
    2828 * @since 10604
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/PrimitiveTransferable.java

    r13206 r14500  
    3030            TagTransferData.FLAVOR, DataFlavor.stringFlavor);
    3131    private final PrimitiveTransferData primitives;
    32     private OsmDataLayer sourceLayer;
     32    private final OsmDataLayer sourceLayer;
    3333
    3434    /**
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r14456 r14500  
    1414import java.awt.Rectangle;
    1515import java.awt.TexturePaint;
     16import java.awt.datatransfer.Transferable;
     17import java.awt.datatransfer.UnsupportedFlavorException;
    1618import java.awt.event.ActionEvent;
    1719import java.awt.geom.Area;
     
    2022import java.awt.image.BufferedImage;
    2123import java.io.File;
     24import java.io.IOException;
    2225import java.util.ArrayList;
    2326import java.util.Arrays;
     
    9598import org.openstreetmap.josm.gui.MapView;
    9699import org.openstreetmap.josm.gui.MapViewState.MapViewPoint;
     100import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
     101import org.openstreetmap.josm.gui.datatransfer.data.OsmLayerTransferData;
    97102import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    98103import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     
    10541059        data.removeSelectionListener(this);
    10551060        data.removeHighlightUpdateListener(this);
     1061        removeClipboardDataFor(this);
     1062    }
     1063
     1064    protected static void removeClipboardDataFor(OsmDataLayer osm) {
     1065        Transferable clipboardContents = ClipboardUtils.getClipboardContent();
     1066        if (clipboardContents != null) {
     1067            try {
     1068                Object o = clipboardContents.getTransferData(OsmLayerTransferData.OSM_FLAVOR);
     1069                if (o instanceof OsmLayerTransferData && osm.equals(((OsmLayerTransferData) o).getLayer())) {
     1070                    ClipboardUtils.clear();
     1071                }
     1072            } catch (UnsupportedFlavorException | IOException e) {
     1073                Logging.error(e);
     1074            }
     1075        }
    10561076    }
    10571077
Note: See TracChangeset for help on using the changeset viewer.