範例

public class ClassA {

private TextLayout textLayout;

public void makeTextLayout( Device device ) {

textLayout = new TextLayout( device );

if ( !textLayout.isDisposed() ) {
//執行某種動作...
}
}
}



解決方案
若要避免資源洩漏,請確定在每個 org.eclipse.swt.graphics.TextLayout 上都呼叫了 dispose()。



public class ClassA {

private TextLayout textLayout;

public void makeTextLayout( Device device ) {

textLayout = new TextLayout( device );

if ( !textLayout.isDisposed() ) {
//執行某種動作...
}
textLayout.dispose();
}
}