示例

public class ClassA {

private Font font;

public void makeFont(Device device, FontData fd) {

font = new Font(device, fd );

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



解决方案
为了避免资源泄漏,请确保对每个 org.eclipse.swt.graphics.Font 都调用 dispose()。
注意:此规则适用于所有形式的 Font 构造函数。


public class ClassA {

private Font font;

public void makeFont(Device device, FontData fd) {

font = new Font(device, fd);

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