-
Notifications
You must be signed in to change notification settings - Fork 52
Fix memory-leak in FigureUtilities by disposing GC on font change #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory-leak in FigureUtilities by disposing GC on font change #816
Conversation
31ba6b8 to
3007c05
Compare
ptziegler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though getGC() is deprecated, it is still API and therefore must not be removed.
|
I wonder if it makes sense to keep the font functionality in the |
fedejeanne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a maintainer of GEF (so please double-check my proposals below) but I would definitely not remove the method since it's still API (being protected means that it can be accessed from subclasses or from the same package).
3007c05 to
2bd7475
Compare
arunjose696
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though
getGC()is deprecated, it is still API and therefore must not be removed.
I’ve reintroduced the method in my change to preserve the previous behavior. However, since this method has been deprecated for over 15 years, it might make sense to mark it for removal if there isnt specific reason to keep it. Given that all methods in this class are static, it’s unlikely that the class is intended to be subclassed, and I don’t see any usage of this method in the Draw2D package. The new logic doesn’t rely on this method, so keeping it seems unnecessary.
I wonder if it makes sense to keep the font functionality in the
FigureUtilitiesor whether it should be moved to theTextUtilities. Perhaps it's possible to re-use the DrawableTextUtilities and have it be accessible from every Figure. Then the references to theFigureUtilitiescan be removed and the old methods be deprecated...
DrawableTextUtilities has non-static methods and this class requires instantiation with a Control source. Looking at how font functionality is currently used, we generally don’t have access to a Control, so moving the logic there isn’t straightforward. Additionally, the TextUtilities parent class computes font information by calling FigureUtilities, so addressing this would also require fixing the existing memory leak.
fedejeanne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
That is true. Though I think all of the font-related methods in the
Each |
ptziegler
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arunjose696 Can you also update your commit message? This part no longer matches the current state:
The now-unused getGC() method which was protected has been removed from the codebase as part of this change.
Before this change figureUtilities created a GC once for an application and then reused it to calculate font/text dimensions. Due to the recent modification of GC in SWT to store Operations, every operation on FigureUtilities that sets the font on the GC (i.e., that calls setFont()) creates a SetFontOperation in the GC. Since that GC is never disposed, these operation accumulate throughout the application lifecycle and constituted a memory leak The current change addresses this issue by instead of crearting a single GC we create a single shell for the lifetime of the application. Whenever a different font needs to be set, the old GC is properly disposed and replaced with a new one created from the shell. This ensures that no GC objects persist indefinitely, effectively preventing the memory leak.
2bd7475 to
c0d2a25
Compare
done |
|
Thanks! |
FigureUtilities create a GC once for an application and then reuse it to calculate font/text dimensions. Due to the modification of GC to store Operations, every operation on FigureUtilities that sets the font on the GC (i.e., that calls setFont()) creates a SetFontOperation in the GC. Since that GC is never dispose, these operation accumulate throughout the application lifecycle and constituted a memory leak
The current change addresses this issue by creating a single shell for the lifetime of the application. Whenever a different font needs to be set, the old GC is properly disposed and replaced with a new one created from the shell. This ensures that no GC objects persist indefinitely, effectively preventing the memory leak. The now unused getGC() method which was protected has been removed from the codebase as part of this change.
Steps to reproduce in vi-eclipse/Eclipse-Platform#443 (comment)
You see that the number of org.eclipse.swt.graphics.GC$SetFontOperation objects in the heap increased (and increases with every GEF diagram that is opened) without this change