Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemy Suen2010-04-20 00:32:09 +0000
committerChris Aniszczyk2010-04-20 14:39:00 +0000
commit217eb828b6de8e37f02cf83f4a7de27679e33e30 (patch)
tree82747ef8ff1cd1678109c0cf82a8b326c9f46fad
parent3daef8f068de0181f2eb63ab88817219335a5819 (diff)
downloadegit-217eb828b6de8e37f02cf83f4a7de27679e33e30.tar.gz
egit-217eb828b6de8e37f02cf83f4a7de27679e33e30.tar.xz
egit-217eb828b6de8e37f02cf83f4a7de27679e33e30.zip
Fix leaks of SWT Color instances
FetchResultTable and PushResultTable was originally using JFace's ColorRegistry for allocating its Color instances. The ColorRegistry will dispose of its Colors when its owning Display is disposed. In the case of the Eclipse workbench, the Display will only ever be disposed when Eclipse itself shuts down. Since the tables create new registries every time they are created, a Color instance is leaked for every request that is made to the registry. The code has been corrected to simply instantiate new, local Color instances directly which are now disposed when the table widget is disposed. Change-Id: Ida8ffcde63a21fe92321643740b8836510a56ea8 Signed-off-By: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchResultTable.java44
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushResultTable.java39
2 files changed, 38 insertions, 45 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchResultTable.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchResultTable.java
index 2697593570..d50a3fced5 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchResultTable.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchResultTable.java
@@ -2,7 +2,6 @@ package org.eclipse.egit.ui.internal.fetch;
import org.eclipse.egit.ui.UIText;
import org.eclipse.jface.layout.TableColumnLayout;
-import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ColumnWeightData;
@@ -10,8 +9,9 @@ import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@@ -39,23 +39,15 @@ class FetchResultTable {
private static final int COLUMN_STATUS_WEIGHT = 7;
- private static final String COLOR_REJECTED_KEY = "REJECTED"; //$NON-NLS-1$
-
- private static final RGB COLOR_REJECTED = new RGB(255, 0, 0);
-
- private static final String COLOR_UPDATED_KEY = "UPDATED"; //$NON-NLS-1$
-
- private static final RGB COLOR_UPDATED = new RGB(0, 255, 0);
-
- private static final String COLOR_UP_TO_DATE_KEY = "UP_TO_DATE"; //$NON-NLS-1$
-
- private static final RGB COLOR_UP_TO_DATE = new RGB(245, 245, 245);
-
private final Composite tablePanel;
private final TableViewer tableViewer;
- private final ColorRegistry colorRegistry;
+ private final Color rejectedColor;
+
+ private final Color updatedColor;
+
+ private final Color upToDateColor;
private Repository db;
@@ -71,10 +63,18 @@ class FetchResultTable {
table.setLinesVisible(true);
table.setHeaderVisible(true);
- colorRegistry = new ColorRegistry(table.getDisplay());
- colorRegistry.put(COLOR_REJECTED_KEY, COLOR_REJECTED);
- colorRegistry.put(COLOR_UPDATED_KEY, COLOR_UPDATED);
- colorRegistry.put(COLOR_UP_TO_DATE_KEY, COLOR_UP_TO_DATE);
+ rejectedColor = new Color(parent.getDisplay(), 255, 0, 0);
+ updatedColor = new Color(parent.getDisplay(), 0, 255, 0);
+ upToDateColor = new Color(parent.getDisplay(), 245, 245, 245);
+
+ tablePanel.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ // dispose of our allocated Color instances
+ rejectedColor.dispose();
+ updatedColor.dispose();
+ upToDateColor.dispose();
+ }
+ });
tableViewer.setContentProvider(new TrackingRefUpdateContentProvider());
tableViewer.setInput(null);
@@ -185,13 +185,13 @@ class FetchResultTable {
case FAST_FORWARD:
case FORCED:
case NEW:
- return colorRegistry.get(COLOR_UPDATED_KEY);
+ return updatedColor;
case NO_CHANGE:
- return colorRegistry.get(COLOR_UP_TO_DATE_KEY);
+ return upToDateColor;
case IO_FAILURE:
case LOCK_FAILURE:
case REJECTED:
- return colorRegistry.get(COLOR_REJECTED_KEY);
+ return rejectedColor;
default:
throw new IllegalArgumentException(NLS.bind(
UIText.FetchResultTable_statusUnexpected, result));
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushResultTable.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushResultTable.java
index 11d3f5a888..893b87ad31 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushResultTable.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushResultTable.java
@@ -13,7 +13,6 @@ import org.eclipse.egit.ui.UIIcons;
import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.components.CenteredImageLabelProvider;
import org.eclipse.jface.layout.TableColumnLayout;
-import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
@@ -27,7 +26,6 @@ import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
@@ -62,25 +60,17 @@ class PushResultTable {
private static final String IMAGE_ADD = "MODE_ADD"; //$NON-NLS-1$
- private static final String COLOR_REJECTED_KEY = "REJECTED"; //$NON-NLS-1$
-
- private static final RGB COLOR_REJECTED = new RGB(255, 0, 0);
-
- private static final String COLOR_UPDATED_KEY = "UPDATED"; //$NON-NLS-1$
-
- private static final RGB COLOR_UPDATED = new RGB(0, 255, 0);
-
- private static final String COLOR_UP_TO_DATE_KEY = "UP_TO_DATE"; //$NON-NLS-1$
-
- private static final RGB COLOR_UP_TO_DATE = new RGB(245, 245, 245);
-
private final TableViewer tableViewer;
private final Composite tablePanel;
private final ImageRegistry imageRegistry;
- private final ColorRegistry colorRegistry;
+ private final Color rejectedColor;
+
+ private final Color updatedColor;
+
+ private final Color upToDateColor;
PushResultTable(final Composite parent) {
tablePanel = new Composite(parent, SWT.NONE);
@@ -98,13 +88,16 @@ class PushResultTable {
imageRegistry.put(IMAGE_ADD, UIIcons.ELCL16_ADD);
imageRegistry.put(IMAGE_DELETE, UIIcons.ELCL16_DELETE);
- colorRegistry = new ColorRegistry(table.getDisplay());
- colorRegistry.put(COLOR_REJECTED_KEY, COLOR_REJECTED);
- colorRegistry.put(COLOR_UPDATED_KEY, COLOR_UPDATED);
- colorRegistry.put(COLOR_UP_TO_DATE_KEY, COLOR_UP_TO_DATE);
+ rejectedColor = new Color(parent.getDisplay(), 255, 0, 0);
+ updatedColor = new Color(parent.getDisplay(), 0, 255, 0);
+ upToDateColor = new Color(parent.getDisplay(), 245, 245, 245);
tablePanel.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
+ // dispose of our allocated Color instances
+ rejectedColor.dispose();
+ updatedColor.dispose();
+ upToDateColor.dispose();
imageRegistry.dispose();
}
});
@@ -258,20 +251,20 @@ class PushResultTable {
public Color getBackground(Object element) {
final RefUpdateElement rue = (RefUpdateElement) element;
if (!rue.isSuccessfulConnection(uri))
- return colorRegistry.get(COLOR_REJECTED_KEY);
+ return rejectedColor;
final Status status = rue.getRemoteRefUpdate(uri).getStatus();
switch (status) {
case OK:
- return colorRegistry.get(COLOR_UPDATED_KEY);
+ return updatedColor;
case UP_TO_DATE:
case NON_EXISTING:
- return colorRegistry.get(COLOR_UP_TO_DATE_KEY);
+ return upToDateColor;
case REJECTED_NODELETE:
case REJECTED_NONFASTFORWARD:
case REJECTED_REMOTE_CHANGED:
case REJECTED_OTHER_REASON:
- return colorRegistry.get(COLOR_REJECTED_KEY);
+ return rejectedColor;
default:
throw new IllegalArgumentException(NLS.bind(
UIText.PushResultTable_statusUnexpected, status));

Back to the top