Memory Question

This is a discussion on Memory Question within the C++ Programming forums, part of the General Programming Boards category; I don't know much about memory. When I was using Blitz Basic, it got rid of everything I had in ...

Memory Question

I don't know much about memory. When I was using Blitz Basic, it got rid of everything I had in memory automatically. So, I have some questions. I'm using Allegro and you have to use destroy_bitmap() for each bitmap you've loaded. But if you don't do that, does the bitmap stay in memory even after the program has finished? And if so, does it ever go away?

Is that why it's necessary to destroy and close all of your objects and windows in the WM_DESTROY message? If so, it's good that I know that now ﻿because I used to never do that ﻿because I saw no need to.

Is that why it's necessary to destroy and close all of your objects and windows in the WM_DESTROY message?

Yes. You're working with the window manager, which isn't technically a part of your process. If you don't destroy the resources then they definitely leak until the system is restarted. So taking care of everything after WM_DESTROY is very important. It falls under the long running program exception.

You should also realize that WM_DESTROY doesn't necesarlly mean your process is ending. It could easily continue on doing other things, just not interacting with the OS via the messages or maybe just that window has been closed.
A rule of thumb:
Always write your programs as though they will be used as a library. This means clean up after yourself because you would expect the same from a library you use.

So, I could never "fill-up" my memory and never be able to get rid of the stuff in it?

'Never' is a strong word. It you use your brain when managing memory usage, you should be okay. But it's easy to grind the system to a screeching halt by leaking away memory. At a certain point it's easier just to reboot than to try and clean up the mess. So don't make the mess in the first place and you'll be happier.