Skip to content

Commit d54cfca

Browse files
committed
De-register resources with zoom support from device
Resources with zoom support are registered at their device so that handles for zoom levels that are not necessary anymore can be disposed. When these resources are destroyed, they are currently not de-registered form their device, potentially leading to resource leaks. This change makes the resources de-register themselves form their device when being destroyed. Supplements #1477
1 parent 5d67ce6 commit d54cfca

File tree

6 files changed

+9
-0
lines changed

6 files changed

+9
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,10 @@ void registerResourceWithZoomSupport(Resource resource) {
959959
resourcesWithZoomSupport.add(resource);
960960
}
961961

962+
void deregisterResourceWithZoomSupport(Resource resource) {
963+
resourcesWithZoomSupport.remove(resource);
964+
}
965+
962966
/**
963967
* Destroys the handles of all the resources in the resource tracker by
964968
* identifying the zoom levels which is not valid for any monitor

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ long initNative(String filename, int zoom) {
11871187

11881188
@Override
11891189
void destroy () {
1190+
device.deregisterResourceWithZoomSupport(this);
11901191
if (memGC != null) memGC.dispose();
11911192
destroyHandle();
11921193
memGC = null;

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Path.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ void cubicToInPixels(float cx1, float cy1, float cx2, float cy2, float x, float
437437

438438
@Override
439439
void destroy() {
440+
device.deregisterResourceWithZoomSupport(this);
440441
zoomLevelToHandle.values().forEach(Gdip::GraphicsPath_delete);
441442
zoomLevelToHandle.clear();
442443
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Pattern.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ void setImageHandle(Image image, int zoom) {
261261

262262
@Override
263263
void destroy() {
264+
device.deregisterResourceWithZoomSupport(this);
264265
for (long handle: zoomLevelToHandle.values()) {
265266
destroyHandle(handle);
266267
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Region.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public boolean contains (Point pt) {
223223

224224
@Override
225225
void destroy () {
226+
device.deregisterResourceWithZoomSupport(this);
226227
zoomToHandle.values().forEach(handle -> OS.DeleteObject(handle));
227228
zoomToHandle.clear();
228229
operations.clear();

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ static float[] checkTransform(float[] elements) {
156156

157157
@Override
158158
void destroy() {
159+
device.deregisterResourceWithZoomSupport(this);
159160
zoomLevelToHandle.values().forEach(Gdip::Matrix_delete);
160161
zoomLevelToHandle.clear();
161162
}

0 commit comments

Comments
 (0)