Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. free is needed when app will exit?

free is needed when app will exit?

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    norish
    wrote on last edited by
    #1

    Hi guys, I have a qustion in windows programing like this. I think free was always needed win16 programing because malloc was implmented by GlobalAlloc and system never free its pointer until GlobalFree called. So it makes a system memory leaks. But nowadays, in win32 system, malloc is implemented by HeapAlloc and do not need call at program exiting anymore, because system frees its heap safely at process died. Is this true or not?

    S 1 Reply Last reply
    0
    • N norish

      Hi guys, I have a qustion in windows programing like this. I think free was always needed win16 programing because malloc was implmented by GlobalAlloc and system never free its pointer until GlobalFree called. So it makes a system memory leaks. But nowadays, in win32 system, malloc is implemented by HeapAlloc and do not need call at program exiting anymore, because system frees its heap safely at process died. Is this true or not?

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      norish wrote:

      But nowadays, in win32 system, malloc is implemented by HeapAlloc and do not need call at program exiting anymore, because system frees its heap safely at process died.

      Strictly you are correct - Windows releases a processes resources when the process terminates. However, it's good practise to release resources explicitly, just in case the code gets reused somewhere that it matters. Use smart pointers/resource handles and it becomes easy enough.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      N 1 Reply Last reply
      0
      • S Stuart Dootson

        norish wrote:

        But nowadays, in win32 system, malloc is implemented by HeapAlloc and do not need call at program exiting anymore, because system frees its heap safely at process died.

        Strictly you are correct - Windows releases a processes resources when the process terminates. However, it's good practise to release resources explicitly, just in case the code gets reused somewhere that it matters. Use smart pointers/resource handles and it becomes easy enough.

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        N Offline
        N Offline
        norish
        wrote on last edited by
        #3

        Thanks for reply. I might be correct after all. :) However, it's good practise to release resources explicitly Your point is the very good manner in most case, I know, especially some system handles (like kernel objects) must explicitly release in the code before progaram exits. So sometimes I use smart pointers for managing such handles. ;)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups