Memory leaks
Posted: Mon Dec 10, 2012 10:53 am
Hi,
I prepared an example with my problem:
In this example, I create one chart. After closing a window with a chart in memory stay 3 links on this chart and GC can not release resources. How can I solve this problem?
I prepared an example with my problem:
Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class TestTChart {
protected Shell shell;
public static void main(String[] args) {
try {
TestTChart window = new TestTChart();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = new Display();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
Button btnNewWindow = new Button(shell, SWT.NONE);
btnNewWindow.setBounds(85, 134, 68, 23);
btnNewWindow.setText("New window");
btnNewWindow.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
new AnotherTestTChart().open();
}
});
}
}
Code: Select all
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import com.steema.teechart.TChart;
public class AnotherTestTChart {
protected Shell shell;
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");
shell.setLayout(new FillLayout());
new TChart(shell, SWT.NONE);
}
}