示例

public class ClassA {

private TextLayout textLayout;

public void makeTextLayout( Device device ) {

textLayout = new TextLayout( device );

if ( !textLayout.isDisposed() ) {
//do something...
}
}
}



解决方案
为了避免资源泄漏,请确保对每个 org.eclipse.swt.graphics.TextLayout 都调用 dispose()。



public class ClassA {

private TextLayout textLayout;

public void makeTextLayout( Device device ) {

textLayout = new TextLayout( device );

if ( !textLayout.isDisposed() ) {
//do something...
}
textLayout.dispose();
}
}