Skip to content

Commit 5489911

Browse files
committed
Add missing image to shared images and resolve resource leak
Currently, a shared image descriptor for a missing image is provided via the ImageDescriptor class. But images created for that descriptor still have to be maintained manually, e.g., by a resource manager or manual disposal. In some cases, this is not done correctly, leading to non-disposed resources. This change adds a shared instance of the missing image that may be reused wherever needed. It is adopted for placeholders, which by now created missing images but never cleaned them up. That resource leak is resolved with the this change.
1 parent 301653e commit 5489911

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/ISharedImages.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,13 @@ public interface ISharedImages {
834834
*/
835835
String IMG_OBJS_DND_TOFASTVIEW = "IMG_OBJS_DND_TOFASTVIEW"; //$NON-NLS-1$
836836

837+
/**
838+
* Identifies the default 'missing' image.
839+
*
840+
* @since 3.137
841+
*/
842+
String IMG_DEF_MISSING = "IMG_DEF_MISSING"; //$NON-NLS-1$
843+
837844
/**
838845
* Retrieves the specified image from the workbench plugin's image registry.
839846
* Note: The returned <code>Image</code> is managed by the workbench; clients

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchImages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ private static final void declareImage(String key, String disabledKey, String pa
117117
*/
118118
@SuppressWarnings("removal")
119119
private static final void declareImages() {
120+
declareImage(ISharedImages.IMG_DEF_MISSING, ImageDescriptor.getMissingImageDescriptor(), true);
121+
120122
// Overlays
121123
declareImage(ISharedImages.IMG_DEC_FIELD_ERROR, PATH_OVERLAY + "error_ovr.svg", true); //$NON-NLS-1$
122124
declareImage(ISharedImages.IMG_DEC_FIELD_WARNING, PATH_OVERLAY + "warning_ovr.svg", true); //$NON-NLS-1$

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchPage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
import org.eclipse.ui.ISaveablesSource;
145145
import org.eclipse.ui.ISelectionListener;
146146
import org.eclipse.ui.ISelectionService;
147+
import org.eclipse.ui.ISharedImages;
147148
import org.eclipse.ui.IShowEditorInput;
148149
import org.eclipse.ui.ISources;
149150
import org.eclipse.ui.IViewPart;
@@ -4038,7 +4039,7 @@ private void handleNullRefPlaceHolders(MUIElement element, MWindow refWin) {
40384039
if (CompatibilityPart.COMPATIBILITY_VIEW_URI.equals(part.getContributionURI())
40394040
&& part.getIconURI() == null) {
40404041
part.getTransientData().put(IPresentationEngine.OVERRIDE_ICON_IMAGE_KEY,
4041-
ImageDescriptor.getMissingImageDescriptor().createImage());
4042+
ISharedImages.get().getImage(ISharedImages.IMG_DEF_MISSING));
40424043
}
40434044
}
40444045

@@ -4055,7 +4056,7 @@ private void replacePlaceholder(MPlaceholder ph) {
40554056
MPart part = modelService.createModelElement(MPart.class);
40564057
part.setElementId(ph.getElementId());
40574058
part.getTransientData().put(IPresentationEngine.OVERRIDE_ICON_IMAGE_KEY,
4058-
ImageDescriptor.getMissingImageDescriptor().createImage());
4059+
ISharedImages.get().getImage(ISharedImages.IMG_DEF_MISSING));
40594060
String label = (String) ph.getTransientData().get(IWorkbenchConstants.TAG_LABEL);
40604061
if (label != null) {
40614062
part.setLabel(label);

0 commit comments

Comments
 (0)