Skip to content

Conversation

@ShahzaibIbrahim
Copy link
Contributor

On Windows SWT, the Device implementation keeps a strong reference to Resource objects via this method:

void registerResourceWithZoomSupport(Resource resource) {
	resourcesWithZoomSupport.add(resource);
}

That means:
Every Resource with zoom support is added to the resourcesWithZoomSupport set in the Device. This is a Set<Resource>, which holds strong references. Because of this, the GC will never collect these resources, even if the application code drops all references, the Device is still referencing them.

To tackle that, we can use the WeakReference (more about it here). That will allows GC to collect the resource.

The only downside I see could be, that every time a Resource object becomes garbage collected, its corresponding WeakReference object still exists in the set, which needs to be cleared. For that, my idea is to clean up the dead references whenever win32_destroyUnusedHandles is called more specifically whenever WM_DISPLAYCHANGE or WM_DPICHANGED event happens.

Fixes: #2335

@github-actions
Copy link
Contributor

github-actions bot commented Jul 23, 2025

Test Results

   546 files  ±0     546 suites  ±0   31m 16s ⏱️ + 2m 33s
 4 412 tests ±0   4 395 ✅ ±0   17 💤 ±0  0 ❌ ±0 
16 718 runs  ±0  16 591 ✅ ±0  127 💤 ±0  0 ❌ ±0 

Results for commit 49819b3. ± Comparison against base commit 7cf1145.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks fine and works as expected. I have only minor comments regarding code style.

On Windows, SWT resources supporting multiple zoom levels are registered
via Device.registerResourceWithZoomSupport(), which retains strong
references to these resources. This prevents garbage collection and
breaks leak detection using Cleaner. Switching to use WeakReference to
allow proper GC behavior and enable the resource tracker to report
non-disposed resources correctly.

Fixes: eclipse-platform#2335
@HeikoKlare HeikoKlare merged commit 89f0bcc into eclipse-platform:master Jul 23, 2025
17 checks passed
@HeikoKlare HeikoKlare deleted the master-367 branch July 23, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-disposed resource tracker not working properly [Win32] Non-disposed resource tracker not working properly

2 participants