範例
public class
ClassA {
private
Shell shell;
public void
makeShell( ) {
shell =
new
Shell( );
if ( !shell.isDisposed() ) {
//執行某種動作...
}
}
}
解決方案
若要避免資源洩漏,請確定在每個 org.eclipse.swt.widgets.Shell 上都呼叫了 dispose()。
附註:這個規則適用於任何形式的 Shell 建構子。
public class
ClassA {
private
Shell shell;
public void
makeShell( ) {
shell =
new
Shell( );
if ( !shell.isDisposed() ) {
//執行某種動作...
}
shell.dispose();
}
}