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 instances
Remove the
dispose
method (since it doesn't work as intended) and modify the constructor of theClockWidget
to add an anonymousDisposeListener
that disposes of the associatedColor
:public ClockWidget(Composite parent, int...