Skip to content

Commit 52ec136

Browse files
committed
fix: resolved memory leaks for SWT Images, Fonts, and TableEditors
1 parent 2261868 commit 52ec136

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeAnalysisEditor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,15 @@ private void createErrorMessageOnEditor()
150150

151151
// Apply bold style to default system font
152152
FontDescriptor boldFontDescriptor = FontDescriptor.createFrom(title.getFont()).setStyle(SWT.BOLD);
153-
title.setFont(boldFontDescriptor.createFont(parent.getDisplay()));
153+
Font boldFont = boldFontDescriptor.createFont(parent.getDisplay());
154+
title.setFont(boldFont);
155+
156+
title.addDisposeListener(e -> {
157+
if (boldFont != null && !boldFont.isDisposed())
158+
{
159+
boldFont.dispose();
160+
}
161+
});
154162

155163
// Subtext explanation
156164
Label explanation = new Label(parent, SWT.CENTER | SWT.WRAP);

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeChartsComposite.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ public void createPartControl(Composite parent, IFile file, String targetName)
146146

147147
private void plotCharts()
148148
{
149+
if (chartComp == null || chartComp.isDisposed())
150+
{
151+
return;
152+
}
153+
149154
for (var child : chartComp.getChildren())
150155
child.dispose();
151156

@@ -310,6 +315,12 @@ private void displayChartAsImage(Composite parent, JFreeChart chart, int width,
310315
Image swtImg = new Image(parent.getDisplay(), imgData);
311316
Label imgLabel = new Label(parent, SWT.NONE);
312317
imgLabel.setImage(swtImg);
318+
imgLabel.addDisposeListener(e -> {
319+
if (swtImg != null && !swtImg.isDisposed())
320+
{
321+
swtImg.dispose();
322+
}
323+
});
313324
}
314325
catch (Exception e)
315326
{

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeOverviewComposite.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
*******************************************************************************/
55
package com.espressif.idf.ui.size;
66

7+
import java.util.ArrayList;
8+
import java.util.List;
9+
710
import org.eclipse.core.resources.IFile;
811
import org.eclipse.swt.SWT;
912
import org.eclipse.swt.custom.TableEditor;
@@ -35,6 +38,7 @@ public class IDFSizeOverviewComposite
3538
private Table table;
3639
private JSONObject overviewJson;
3740
private Font boldFont;
41+
private List<TableEditor> tableEditors = new ArrayList<>();
3842

3943
private enum MemoryUnit
4044
{
@@ -113,10 +117,28 @@ public void createPartControl(Composite parent, IFile file, String targetName)
113117
// Bold header
114118
Font headerFont = applyBold(table.getFont());
115119
table.setFont(headerFont);
120+
parent.addDisposeListener(e -> {
121+
if (boldFont != null && !boldFont.isDisposed())
122+
{
123+
boldFont.dispose();
124+
}
125+
});
116126
}
117127

118128
private void populateTable()
119129
{
130+
if (table == null || table.isDisposed()) return;
131+
132+
for (TableEditor editor : tableEditors)
133+
{
134+
if (editor.getEditor() != null && !editor.getEditor().isDisposed())
135+
{
136+
editor.getEditor().dispose();
137+
}
138+
editor.dispose();
139+
}
140+
tableEditors.clear();
141+
120142
table.removeAll();
121143

122144
// Defensive check: Handle unexpected empty data gracefully to prevent UI crash.
@@ -175,6 +197,7 @@ private void createProgressBar(int rowIndex, long used, long total)
175197
return;
176198

177199
TableEditor editor = new TableEditor(table);
200+
tableEditors.add(editor);
178201
editor.grabHorizontal = true;
179202
editor.grabVertical = true;
180203
editor.horizontalAlignment = SWT.FILL;

0 commit comments

Comments
 (0)