aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemy Suen2010-04-18 13:53:24 (EDT)
committerChris Aniszczyk2010-04-20 10:59:24 (EDT)
commit21fe73b3c4a6449a5c59ac621c2abda3159823f2 (patch)
tree00fc8da6be9f58afd93688793a1a6cee2ed63468
parent3236fe48a1b7b54124b6a11c187b3f1910a60e06 (diff)
downloadegit-21fe73b3c4a6449a5c59ac621c2abda3159823f2.zip
egit-21fe73b3c4a6449a5c59ac621c2abda3159823f2.tar.gz
egit-21fe73b3c4a6449a5c59ac621c2abda3159823f2.tar.bz2
Dispose of any instantiated images when the label provider isrefs/changes/79/579/2
disposed (bug 309601). ImageDescriptors creates new SWT images every time createImage() is invoked. Images need to be explicitly disposed when they are no longer needed or the application will eventually run out of resources. A map is now kept of all the images that have been instantiated so clean-up can be performed when the label provider is disposed. Change-Id: Ie2530aac18ac6c70011ec3bba15278fc253599c2 Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java82
1 files changed, 48 insertions, 34 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java
index 3cc1e7e..bbbee21 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java
@@ -12,6 +12,8 @@ package org.eclipse.egit.ui.internal.repository;
import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -27,6 +29,7 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeColumn;
@@ -36,6 +39,11 @@ import org.eclipse.swt.widgets.TreeColumn;
public class RepositoriesViewLabelProvider extends BaseLabelProvider implements
ITableLabelProvider {
+ /**
+ * A map of regular images to their decorated counterpart.
+ */
+ private Map<Image, Image> decoratedImages = new HashMap<Image, Image>();
+
// private DefaultInformationControl infoControl;
/**
@@ -181,6 +189,16 @@ public class RepositoriesViewLabelProvider extends BaseLabelProvider implements
}
}
+ @Override
+ public void dispose() {
+ // dispose of our decorated images
+ for (Image image : decoratedImages.values()) {
+ image.dispose();
+ }
+ decoratedImages.clear();
+ super.dispose();
+ }
+
private Image decorateImage(final Image image, Object element) {
RepositoryTreeNode node = (RepositoryTreeNode) element;
@@ -193,23 +211,7 @@ public class RepositoriesViewLabelProvider extends BaseLabelProvider implements
try {
String branch = node.getBranch();
if (refName.equals(branch)) {
- CompositeImageDescriptor cd = new CompositeImageDescriptor() {
-
- @Override
- protected Point getSize() {
- return new Point(image.getBounds().width, image
- .getBounds().width);
- }
-
- @Override
- protected void drawCompositeImage(int width, int height) {
- drawImage(image.getImageData(), 0, 0);
- drawImage(UIIcons.OVR_CHECKEDOUT.getImageData(), 0,
- 0);
-
- }
- };
- return cd.createImage();
+ return getDecoratedImage(image);
}
} catch (IOException e1) {
// simply ignore here
@@ -223,23 +225,7 @@ public class RepositoriesViewLabelProvider extends BaseLabelProvider implements
for (IProject proj : ResourcesPlugin.getWorkspace().getRoot()
.getProjects()) {
if (proj.getLocation().equals(new Path(file.getAbsolutePath()))) {
- CompositeImageDescriptor cd = new CompositeImageDescriptor() {
-
- @Override
- protected Point getSize() {
- return new Point(image.getBounds().width, image
- .getBounds().width);
- }
-
- @Override
- protected void drawCompositeImage(int width, int height) {
- drawImage(image.getImageData(), 0, 0);
- drawImage(UIIcons.OVR_CHECKEDOUT.getImageData(), 0,
- 0);
-
- }
- };
- return cd.createImage();
+ return getDecoratedImage(image);
}
}
return image;
@@ -249,4 +235,32 @@ public class RepositoriesViewLabelProvider extends BaseLabelProvider implements
}
}
+ private Image getDecoratedImage(final Image image) {
+ // check if we have a decorated image yet or not
+ Image decoratedImage = decoratedImages.get(image);
+ if (decoratedImage == null) {
+ // create one
+ CompositeImageDescriptor cd = new CompositeImageDescriptor() {
+
+ @Override
+ protected Point getSize() {
+ Rectangle bounds = image.getBounds();
+ return new Point(bounds.width, bounds.height);
+ }
+
+ @Override
+ protected void drawCompositeImage(int width, int height) {
+ drawImage(image.getImageData(), 0, 0);
+ drawImage(UIIcons.OVR_CHECKEDOUT.getImageData(), 0,
+ 0);
+
+ }
+ };
+ decoratedImage = cd.createImage();
+ // store it
+ decoratedImages.put(image, decoratedImage);
+ }
+ return decoratedImage;
+ }
+
}