It is necessary to know how many resources are allocated in order to know if the leak has been plugged or not. Fortunately, SWT provides a mechanism to do this via the Display
and the DeviceData
classes. Normally, this is done by a separate plug-in, but in this example ClockView
will be modified to show this behavior.
At the start of the
ClockView
class'createPartControl()
method, add a call to obtain the number of allocatedObjects
, viaDeviceData
of theDisplay
class:public void createPartControl(Composite parent) { Object[] oo=parent.getDisplay().getDeviceData().objects;
Iterate through the allocated
objects
counting how many are instances ofColor
:int c = 0; for (int i = 0; i < oo.length; i++) if (oo[i] instanceof Color) c++;
Print the count to the standard error stream:
System.err.println("There are " + c + " Color instances");
Now run the code in debug mode and show the Clock View. The following will be displayed in the host Eclipse...