Time for action – plugging the leak
Now that the leak has been discovered, it needs to be fixed. The solution is to call dispose
on the Color
once the view itself is removed.
A quick investigation of the ClockWidget
suggests that overriding dispose
might work, though this is not the correct solution; see later for why.
- Create a dispose method in
ClockWidget
with the following code:@Override public void dispose() { if (color != null && !color.isDisposed()) color.dispose(); super.dispose(); }
- Run the target Eclipse application in debug mode (with the tracing enabled, as before) and open and close the view. The output will show something like this:
There are 87 Color instances There are 91 Color instances There are 94 Color instances There are 98 Color ...
Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.