mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Updated broken finalizer in main with shutdown hook.
This commit is contained in:
@@ -45,6 +45,15 @@ public final class Main {
|
|||||||
*/
|
*/
|
||||||
public static void main(final String[] args) {
|
public static void main(final String[] args) {
|
||||||
ExceptionHandler.registerErrorHandling();
|
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 {
|
try {
|
||||||
Singletons.setModel(FModel.SINGLETON_INSTANCE);
|
Singletons.setModel(FModel.SINGLETON_INSTANCE);
|
||||||
Singletons.setView(FView.SINGLETON_INSTANCE);
|
Singletons.setView(FView.SINGLETON_INSTANCE);
|
||||||
@@ -60,19 +69,4 @@ public final class Main {
|
|||||||
ErrorViewer.showError(exn);
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user