Skip to content

Commit ce71b80

Browse files
committed
Resolve "SWT Resource was not properly disposed" for "Statistics"
* implement dispose for `TmfPieChartViewer` * use `dispose` properly
1 parent d487cf2 commit ce71b80

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/viewers/piecharts/PieChartViewerStateNoContentSelected.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015 Ericsson
2+
* Copyright (c) 2015, 2025 Ericsson and others
33
*
44
* All rights reserved. This program and the accompanying materials are
55
* made available under the terms of the Eclipse Public License 2.0 which
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* Alexis Cabana-Loriaux - Initial API and implementation
13+
* Alexander Fedorov (ArSysOp) - fix "SWT Resource was not properly disposed"
1314
*
1415
*******************************************************************************/
1516

@@ -43,13 +44,7 @@ public PieChartViewerStateNoContentSelected(final TmfPieChartViewer context) {
4344
synchronized (context) {
4445
if (!context.isDisposed()) {
4546
// Have to get rid of the time-range PieChart
46-
if (context.getTimeRangePC() != null) {
47-
if (!context.getTimeRangePC().isDisposed()) {
48-
context.getTimeRangePC().dispose();
49-
}
50-
context.setTimeRangePC(null);
51-
}
52-
47+
context.disposeTimeRangePC();
5348
context.updateGlobalPieChart();
5449
// update the global chart so it takes all the place
5550
context.getGlobalPC().getLegend().setPosition(SWT.RIGHT);

tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/viewers/piecharts/TmfPieChartViewer.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2015, 2020 Ericsson
2+
* Copyright (c) 2015, 2025 Ericsson and others
33
*
44
* All rights reserved. This program and the accompanying materials are
55
* made available under the terms of the Eclipse Public License 2.0 which
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* Alexis Cabana-Loriaux - Initial API and implementation
13+
* Alexander Fedorov (ArSysOp) - fix "SWT Resource was not properly disposed"
1314
*
1415
*******************************************************************************/
1516

@@ -442,17 +443,11 @@ public synchronized void reinitializeCharts() {
442443
if (isDisposed()) {
443444
return;
444445
}
445-
446-
if (getGlobalPC() != null && !getGlobalPC().isDisposed()) {
447-
getGlobalPC().dispose();
448-
}
446+
disposeGlobalPC();
449447
fGlobalPC = new TmfPieChart(this, SWT.NONE);
450448
getGlobalPC().getTitle().setText(fGlobalPCname);
451449
getGlobalPC().getAxisSet().getXAxis(0).getTitle().setText(""); //Hide the title over the legend //$NON-NLS-1$
452-
if (getTimeRangePC() != null && !getTimeRangePC().isDisposed()) {
453-
getTimeRangePC().dispose();
454-
fTimeRangePC = null;
455-
}
450+
disposeTimeRangePC();
456451
layout();
457452
setCurrentState(new PieChartViewerStateNoContentSelected(this));
458453
}
@@ -582,4 +577,26 @@ public void select(String id) {
582577
pieChart.redraw();
583578
}
584579
}
580+
581+
@Override
582+
public void dispose() {
583+
disposeGlobalPC();
584+
disposeTimeRangePC();
585+
super.dispose();
586+
}
587+
588+
void disposeGlobalPC() {
589+
if (fGlobalPC != null && !fGlobalPC.isDisposed()) {
590+
fGlobalPC.dispose();
591+
fGlobalPC = null;
592+
}
593+
}
594+
595+
void disposeTimeRangePC() {
596+
if (fTimeRangePC != null && !fTimeRangePC.isDisposed()) {
597+
fTimeRangePC.dispose();
598+
fTimeRangePC = null;
599+
}
600+
}
601+
585602
}

tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/viewers/statistics/TmfStatisticsViewer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2012, 2020 Ericsson
2+
* Copyright (c) 2012, 2025 Ericsson and others
33
*
44
* All rights reserved. This program and the accompanying materials are
55
* made available under the terms of the Eclipse Public License 2.0 which
@@ -13,6 +13,7 @@
1313
* Alexandre Montplaisir - Port to ITmfStatistics provider
1414
* Patrick Tasse - Support selection range
1515
* Bernd Hufmann - Fix range selection updates
16+
* Alexander Fedorov (ArSysOp) - fix "SWT Resource was not properly disposed"
1617
*******************************************************************************/
1718

1819
package org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics;
@@ -186,7 +187,7 @@ private void internalDispose() {
186187

187188
// Clean the model for this viewer
188189
TmfStatisticsTreeManager.removeStatTreeRoot(getTreeID());
189-
fPieChartViewer.reinitializeCharts();
190+
fPieChartViewer.dispose();
190191
}
191192

192193
// ------------------------------------------------------------------------

0 commit comments

Comments
 (0)