dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: freeing memory in the WM_DESTROY message

  1. #1
    Join Date
    Sep 2019
    Posts
    11

    freeing memory in the WM_DESTROY message

    Hello,

    I have a question regarding the usual freeing of memory in the WM_DESTROY message of the main windows of the program, before calling the PostQuitMessage(0)..


    Is it any problem if acciddentally some memory previously allocated (by malloc, etc) is not freed in the WM_DESTROY message?


    Best,
    D Narcis

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,972

    Re: freeing memory in the WM_DESTROY message

    When a program (process) terminates, the 'os' automatically frees all still-allocated memory. However, it is good practice not to rely upon this and should free what has been allocated.

    Also note, that if you are writing a WIN32 gui program, you can free memory after the 'message' pump loop has terminated (which is what WM_DESTROY effectively does with the PostQuitMessage() - terminates the loop). Where it's best to do depends upon where the memory has been allocated (scope).
    Last edited by 2kaud; December 4th, 2019 at 05:40 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.4.3)

  3. #3
    Join Date
    Sep 2019
    Posts
    11

    Re: freeing memory in the WM_DESTROY message

    Ok, so basically would not cause any problem to the memory pool.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)