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 ...

  1. #1
    C++ Newbie
    Join Date
    Aug 2005
    Posts
    55

    Question 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?

  2. #2
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    Most OS's will free the memory allocated to your process when the program terminates. Some won't though, and for longer running programs you should be careful to free any memory you allocate.
    Just because I don't care doesn't mean I don't understand.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    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.

  4. #4
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    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.
    Just because I don't care doesn't mean I don't understand.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    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.

  6. #6
    C++ Newbie
    Join Date
    Aug 2005
    Posts
    55
    So, I could never "fill-up" my memory and never be able to get rid of the stuff in it?

  7. #7
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    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.
    Just because I don't care doesn't mean I don't understand.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. heap vs stack memory question
    By donglee in forum C++ Programming
    Replies: 4
    Last Post: 01-23-2009, 04:34 PM
  2. Pointer memory question
    By Edo in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2009, 03:36 AM
  3. Memory question
    By John_L in forum Tech Board
    Replies: 8
    Last Post: 06-02-2008, 11:06 PM
  4. Another Dynamic Memory Question
    By SirCrono6 in forum C++ Programming
    Replies: 6
    Last Post: 03-02-2005, 12:10 PM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 02:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21