Do I have to dispose stuff when the game ends?

When the user exits the game, do I have to manually dispose any custom created bitmaps and such?

Probably not but I better make sure 😛 .
When the game closes, Windows takes care of the entire bit of memory the application had. If you don't dispose a bitmap, it'll stay in memory until it is disposed. If you don't dispose a bitmap and you close the game, Windows reclaims the memory space, so the bitmap will be deleted.

So no, you don't have to worry about deleting them at shutdown. Just make sure you don't create a memory leak by creating more bitmaps under the same name, while not disposing the old bitmaps. They will stay in memory until the game closes and windows deletes them. Then you have a problem.
As explained, you'll get all your memory back when the game terminates, so you don't need to manually dispose anything on exit.


As for disposing stuff during runtime, you absolutely need to dispose your sprites/windows/planes before they lose all references because of the potential of causing a Game.exe crash as explained here: http://forums.rpgmakerweb.com/index.php?/topic/17400-graphical-object-global-reference-ace/?p=206688. Disposing bitmaps that you haven't cached is also a good idea, they will still be garbage collected if orphaned even if not disposed but the collection does seem to be more leaky and slower than if not. There is no actual proven problem with just letting the GC take care of it, but it is just good practice to make sure it is taken care of (plus, you never know if at some point in the future it will be linked to some other obscure error - the problem discussed in the linked thread went undiscovered for years in VX and almost a year in ACE, despite my testing for it). And if you happen to accumulate 10,000 bitmaps in memory at any given time, you'll have a GDI overflow and crash. Though something is very wrong if that happens.
Great 🙂 .
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/do-i-have-to-dispose-stuff-when-the-game-ends.21727/