1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

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
This commit is contained in:
Jonah Graham 2022-02-25 11:39:22 -05:00
parent 45237eed0b
commit 687503911b

View file

@ -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<URL, Image> loadedIcons = new HashMap<>();
private List<Image> loadedIcons = new ArrayList<>();
private static Map<Class<? extends AbstractPage>, Class<? extends ICPropertyTab>> 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;
}