eclipse-nattable / nattable

High performance SWT data grid
https://eclipse.dev/nattable/
Eclipse Public License 2.0
15 stars 6 forks source link

GC not reliably closed everywhere #94

Closed thomasa299792 closed 2 months ago

thomasa299792 commented 3 months ago

The GC might not be disposed in MaxCellBounds.getPreferredRowHeights() if the method exits due to an exception.

That exception might have been https://github.com/eclipse-nattable/nattable/issues/93 .

Observed in v2.0.5 with an SWT non-dispose handler set by Resource.setNonDisposeHandler( ... ).

Current code:

        GC gc = gcFactory.createGC();
        if (gc != null) {
            int[] rowHeights = new int[rowPositions.length];
            for (int i = 0; i < rowPositions.length; i++) {
                rowHeights[i] = getPreferredRowHeight(layer, rowPositions[i], configRegistry, gc);
            }
            gc.dispose();
            ...

One possible fix:

        GC gc = gcFactory.createGC();
        if (gc != null) {
            int[] rowHeights = new int[rowPositions.length];
            try {
                for (int i = 0; i < rowPositions.length; i++) {
                    rowHeights[i] = getPreferredRowHeight(layer, rowPositions[i], configRegistry, gc);
                }
            }
            finally {
                gc.dispose();
            }
fipro78 commented 2 months ago

Changed the issue title as I noticed other places where the try...finally was also missing.