r/javahelp • u/Altugsalt • 2d ago
Per-Class cleanups when shutting down
Hello, I am creating a save system however it currently depends on memory limits. When the map fills up, it dumps to disk and starts filling memory again from start. When the program shuts down, I want the class responsible for saving the data to run a cleanup function the dump the half-full map to disk. I have seen several ways of doing this however I couldn't really decide what is the best choice. Thanks
7
Upvotes
2
u/Duente_Zaibatsu 2d ago
What context are you running your application? If Swing or similar, there are shutdown hooks, or even better, do a pre-close method, prior to shutdown, if it could be fallible, and you could abort prior to exit