示例
protected
void
finalize()
throws
Throwable {
try
{
getApplet().destroy();
}
finally
{
super
.finalize();
}
}
private
Applet
getApplet() {
if
(_applet ==
null
) {
_applet =
new
Applet();
}
return
_applet;
}
private
Applet
_applet =
null
;
解决方案
使用显式调用的 cleanup 方法来代替 finalize() 方法。
protected
void
free() {
getApplet().destroy();
}
private
Applet
getApplet() {
if
(_applet ==
null
) {
_applet =
new
Applet();
}
return
_applet;
}
private
Applet
_applet =
null
;