Laurens Posted October 3, 2010 Share Posted October 3, 2010 Hi, This is probably a real simple question but I was unable to find a conclusive answer searching the web for a bit. I have a singleton that manages some pointers to objects that have been new'ed at some point. Now, if my game has a clean exit, will the O/S (Windows/Linux/Mac) automatically reclaim the memory that my game was using without me having actually deleted the singleton and the pointers it manages? And what if my game crashes? Will the O/S still reclaim the memory? Thanks! Quote Link to comment Share on other sites More sharing options...
Canardia Posted October 3, 2010 Share Posted October 3, 2010 Yeah, the OS will clean up the memory, even if the game crashes, but it's not a good way to do things. Write your code so that it doesn't crash and delete the memory yourself. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Laurens Posted October 3, 2010 Author Share Posted October 3, 2010 Good to know, thanks! Quote Link to comment Share on other sites More sharing options...
Mumbles Posted October 4, 2010 Share Posted October 4, 2010 It's still always a good idea to free old mallocs (and delete old news) that you no longer need... You just never know how much RAM another system will have available. Quote LE Version: 2.50 (Eventually) Link to comment Share on other sites More sharing options...
Canardia Posted October 4, 2010 Share Posted October 4, 2010 The biggest problem when not freeing your classes with delete, is that their destructors will never get called. So if you do some file I/O in the destructor (like deleting temp files), they will never get deleted, so it's not always only a issue about freeing the memory. Why do you think you have thousand of temp files in your temp folder? They are mostly remains from crashed programs, or not responding programs which you had to terminate from the process list in task manager. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Laurens Posted October 4, 2010 Author Share Posted October 4, 2010 The object in question does not open any files or anything so that would have not been a problem, but to ensure some future requirement won't change this I opted to no longer use singletons but instead use the service locator pattern that does give me control over when I want to delete the managers. Cheers! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.