0

I know that there are several other threads talking on SWT on No More Handles errors, e.g., SWT No More Handles.

However, I am facing a problem I have when I use a ColumnLabelProvider for a TableViewer to provide an Image for each Column of the table using the ColumnLabelProvider.getImage() method.

The problem appears when I load tables with large amounts of data (e.g., 8000 columns).

I instantiate the different images (only two in my case) as static properties of the View class containing the TableViewer to avoid 8000 instances of the same image:

private static Image FAILURE_IMAGE = UIPlugin.imageDescriptorFromPlugin(
        Activator.PLUGIN_ID, "/icons/failure.gif").createImage();

/** {@link Image} used to display a test case as run successfully. */
private static Image OK_IMAGE = UIPlugin.imageDescriptorFromPlugin(
        Activator.PLUGIN_ID, "/icons/ok.gif").createImage();

In the ColumnLabelProvider I simply return these images:

public Image getImage(Object element) {
    if (ok)
        return FAILURE_IMAGE;
    else
        return OK_IMAGE;
}

However, I get the No More Handles error.

Do I do anything wrong? Is the code to create the Images as static fields bad or faulty? Shouldn't SWT be able to display tables with 8000 columns having icons.

Community
  • 1
  • 1
Claas Wilke
  • 1,951
  • 1
  • 18
  • 29
  • 1
    OK, sorry, I found the problem. The code above actually works as caching the images as static fields. I had two ColumnLabelProviders within my code and the second one was not using the static fields but created a new Image for each column. Changing the code to the code outlined above solve the problem. – Claas Wilke Apr 19 '13 at 08:32
  • 1
    Post your finding as answer and then accept it. – Favonius Apr 19 '13 at 11:02
  • 2
    its not a good way to declare images as static fields. if the image code throws exception, your entire application breaks. Have a separate cache for resources that you are using and always reuse resources ( font, color..etc) – sambi reddy Apr 19 '13 at 17:00

0 Answers0