From 687503911bafffe1f25af9e4b9e080b407fcc556 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Fri, 25 Feb 2022 11:39:22 -0500 Subject: [PATCH] Dispose of icons in managed build settings pages In Bug 531915 the code was rewritten to use imageDescriptorFromBundle, which lead to url being null all the time. This meant only the last loaded image was being disposed properly. There fix to Bug 531915 had another side effect - it changed the caching of icons from the Image to the ImageDescriptor. As it has been ~4 years without the image being cached, I suppose it is ok to leave it not cached and instead I store the images to be disposed of in a list. Change-Id: Id3427ebfc8720da52132bd8f11714bba1e2cd0bf --- .../src/org/eclipse/cdt/ui/newui/AbstractPage.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractPage.java index 8de06a776fd..24e931940ef 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/AbstractPage.java @@ -21,7 +21,6 @@ package org.eclipse.cdt.ui.newui; import java.io.File; import java.lang.reflect.InvocationTargetException; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -151,7 +150,7 @@ public abstract class AbstractPage extends PropertyPage implements IPreferencePa private static final String PREF_ASK_REINDEX = "askReindex"; //$NON-NLS-1$ - private Map loadedIcons = new HashMap<>(); + private List loadedIcons = new ArrayList<>(); private static Map, Class> recentTabs = new HashMap<>(); private final Image IMG_WARN = CDTSharedImages.getImage(CDTSharedImages.IMG_OBJS_REFACTORING_WARNING); @@ -1052,7 +1051,7 @@ public abstract class AbstractPage extends PropertyPage implements IPreferencePa if (displayedConfig) forEach(ICPropertyTab.DISPOSE); // Dispose any loaded images - for (Image img : loadedIcons.values()) + for (Image img : loadedIcons) img.dispose(); loadedIcons.clear(); @@ -1196,7 +1195,6 @@ public abstract class AbstractPage extends PropertyPage implements IPreferencePa private Image getIcon(IConfigurationElement config) { ImageDescriptor idesc = null; - URL url = null; String iconName = config.getAttribute(IMAGE_NAME); if (iconName != null) { idesc = ResourceLocator.imageDescriptorFromBundle( @@ -1206,7 +1204,7 @@ public abstract class AbstractPage extends PropertyPage implements IPreferencePa if (idesc == null) return null; Image img = idesc.createImage(); - loadedIcons.put(url, img); + loadedIcons.add(img); return img; }