Fix Resource leak tracking issue on Windows #2338
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On Windows SWT, the Device implementation keeps a strong reference to Resource objects via this method:
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, theDeviceis 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
Resourceobject becomes garbage collected, its correspondingWeakReferenceobject 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 wheneverWM_DISPLAYCHANGEorWM_DPICHANGEDevent happens.Fixes: #2335