Time for action – finding the leak

It is necessary to know how many resources are allocated in order to know whether the leak has been plugged or not. Fortunately, SWT provides a mechanism to do this via the Display and the DeviceData class. Normally, this is done by a separate plug-in, but in this example, the ClockView will be modified to show this behavior.

  1. At the start of the ClockView class's createPartControl method, add a call to obtain the number of allocated objects, via the DeviceData of the Display class:
    public void createPartControl(Composite parent) {
      Object[] objects = parent.getDisplay().getDeviceData().objects;
  2. Iterate through the allocated objects, counting how many are instances of Color:
     int count = 0; for (int i = 0; i < objects.length; ...

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.