CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2013
    Posts
    34

    what data should be cleaned up/released?

    I've been wondering about this for a while, but not having run into any problems yet, I haven't worried about it, but as I write bigger and bigger codes, i'm thinking this is something I should look in to.

    what kind of data should be cleared before closing? and how should you clear it?
    (so far I've only been deleting device contexts with DeleteDC, but I would think, if I have to clear that, I'd have to clear more)

    with local variables, since it looks like they get re-called every time that function is run, do they have to be cleared at the end of the function?

    or does windows take care of this stuff for you?

    thank you

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: what data should be cleaned up/released?

    Windows will free up any memory and system resources your program is using when it terminates. On the other hand, it's good practice to do it yourself anyway. You should delete any memory you allocated with new, and any GDI objects you have used.

  3. #3
    Join Date
    Apr 2013
    Posts
    34

    Re: what data should be cleaned up/released?

    Thank you! that should be easy enough to remember, and it's something I'll try to make a habit of doing, since I do plan to program for other platforms at some point

    thanks again!

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: what data should be cleaned up/released?

    Don't rely on Windows to do it for you on program termination. Just get in the habit of cleaning up after yourself while the program is running; otherwise you run the risk of running out of resources while the program runs. See msdn for info on the api you are using for the corresponding delete method. In general, anything in Windows that allocates some form of handle will need to be freed using the appropriate cleanup method - msdn will tell you what that is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured