Updated broken finalizer in main with shutdown hook.

This commit is contained in:
Doublestrike
2012-03-04 05:03:42 +00:00
parent fe2eb6625c
commit bf1fe60b54

View File

@@ -45,6 +45,15 @@ public final class Main {
*/
public static void main(final String[] args) {
ExceptionHandler.registerErrorHandling();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
// Only works if the program is not ABORTed / KILLed.
// Used instead of a finalizer to avoid leak issues.
Singletons.getModel().close();
}
}));
try {
Singletons.setModel(FModel.SINGLETON_INSTANCE);
Singletons.setView(FView.SINGLETON_INSTANCE);
@@ -60,19 +69,4 @@ public final class Main {
ErrorViewer.showError(exn);
}
}
/**
* Destructor for FModel.
*
* @throws Throwable
* indirectly
*/
@Override
protected void finalize() throws Throwable {
System.out.println("Running finalizer");
// NOT WORKING
// this should call close in model,
// should probably be attached to frame close method
super.finalize();
}
}