Példa
protected void finalize() throws Throwable {
try {
getContext().close();
}
catch (NamingException exc) {
LogUtility.log(exc);
}
finally {
super .finalize();
}
}

private Context getContext() {
return _context;
}

private transient Context _context;
Megoldás
A finalize() metódus helyett inkább javasolt egy külön, explicit módon meghívott metódus írása, ami elvégzi takarítást.
public void free() {
try {
getContext().close();
}
catch (NamingException exc) {
LogUtility.log(exc);
}
}

private Context getContext() {
return _context;
}

private transient Context _context;