void releaseChildren () { Control [] children = _getChildren (); for (int i=0; i<children.length; i++) { Control child = children [i]; if (!child.isDisposed ()) child.releaseResources (); }}
其中的_getChildren()方法通過OS對象的方法遍曆控制項的子控制項,然後匯總到一起分別調用releaseResources()方法釋放控制項和控制代碼。
回到上次的SimplestSWT的例子:
package sean.test.swt;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class SimplestSWT { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }}