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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Process exit memory released?

Process exit memory released?

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancequestion
13 Posts 6 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.
  • V Offline
    V Offline
    vipin_nvk
    wrote on last edited by
    #1

    When process exit, will the memory that's left undeleted be returned to OS? My application is a C++ application.

    L R C M N 5 Replies Last reply
    0
    • V vipin_nvk

      When process exit, will the memory that's left undeleted be returned to OS? My application is a C++ application.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Yes. And JFYI, OS always reclaims memory after the process (application) exits. If your process runs for some time and doesn't care to release unwanted memory then it won't be reclaimed by the OS and the memory "leaks".

      ...byte till it megahertz... my donation to web rubbish

      V 1 Reply Last reply
      0
      • V vipin_nvk

        When process exit, will the memory that's left undeleted be returned to OS? My application is a C++ application.

        R Offline
        R Offline
        Rajesh R Subramanian
        wrote on last edited by
        #3

        Bleedingfingers gave you the correct answer.

        vipin_nvk wrote:

        My application is a C++ application.

        The language used to build your program is irrelevant. The OS will ALWAYS take it back after your program is done!

        It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.

        1 Reply Last reply
        0
        • L Lost User

          Yes. And JFYI, OS always reclaims memory after the process (application) exits. If your process runs for some time and doesn't care to release unwanted memory then it won't be reclaimed by the OS and the memory "leaks".

          ...byte till it megahertz... my donation to web rubbish

          V Offline
          V Offline
          vipin_nvk
          wrote on last edited by
          #4

          If your process runs for some time and doesn't care to release unwanted memory then it won't be reclaimed by the OS and the memory "leaks". This part of your reply is confusing, does it mean that if I allocate memory in my program but fail to release it properly during application exit / if the application has crashed / terminated from the task manager, will this allocated memory (allocated during program execution) will not be returned to the OS and result in memory leak? Thanx in advance

          L 1 Reply Last reply
          0
          • V vipin_nvk

            If your process runs for some time and doesn't care to release unwanted memory then it won't be reclaimed by the OS and the memory "leaks". This part of your reply is confusing, does it mean that if I allocate memory in my program but fail to release it properly during application exit / if the application has crashed / terminated from the task manager, will this allocated memory (allocated during program execution) will not be returned to the OS and result in memory leak? Thanx in advance

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            No no. Suppose you have a code like this in your app

            void main()
            {
            while(true)
            {
            int *array = new int[100];
            }
            }

            As long as the app runs, you will have memory leak since you aren't deleting the allocated memory. And it doesn't really matter if the app crashes or ends normally, for the OS the app has ceased to exist and it cleans up. It is your (the app's) data files, network connections etc that would encounter trouble when the app crashes. Clear?

            ...byte till it megahertz... my donation to web rubbish

            V 1 Reply Last reply
            0
            • L Lost User

              No no. Suppose you have a code like this in your app

              void main()
              {
              while(true)
              {
              int *array = new int[100];
              }
              }

              As long as the app runs, you will have memory leak since you aren't deleting the allocated memory. And it doesn't really matter if the app crashes or ends normally, for the OS the app has ceased to exist and it cleans up. It is your (the app's) data files, network connections etc that would encounter trouble when the app crashes. Clear?

              ...byte till it megahertz... my donation to web rubbish

              V Offline
              V Offline
              vipin_nvk
              wrote on last edited by
              #6

              Yes, so to my understanding, all the memory allocated using new when a process is running is allocated from the process memory heap and it will be eventually reclaimed by the OS once the process terminates.. right?

              R 2 Replies Last reply
              0
              • V vipin_nvk

                Yes, so to my understanding, all the memory allocated using new when a process is running is allocated from the process memory heap and it will be eventually reclaimed by the OS once the process terminates.. right?

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #7

                vipin_nvk wrote:

                Yes, so to my understanding, all the memory allocated using new when a process is running is allocated from the process memory heap and it will be eventually reclaimed by the OS once the process terminates.. right?

                Right!

                It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.

                1 Reply Last reply
                0
                • V vipin_nvk

                  Yes, so to my understanding, all the memory allocated using new when a process is running is allocated from the process memory heap and it will be eventually reclaimed by the OS once the process terminates.. right?

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #8

                  You could read these couple of very good essays: Inside memory allocation[^] Memory damage primer[^] They aren't particularly explaining how the OS reclaims the resources after a process exits, but nevertheless they make a great read.

                  It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.

                  V 1 Reply Last reply
                  0
                  • V vipin_nvk

                    When process exit, will the memory that's left undeleted be returned to OS? My application is a C++ application.

                    C Offline
                    C Offline
                    Cedric Moonen
                    wrote on last edited by
                    #9

                    In addition to other answer, I just wantewd to say that it is very good practice to always release the memory you are using. This will reduce the risk of memory leaks you will have when the application is running (see another answer about memory leaks).

                    Cédric Moonen Software developer
                    Charting control [v3.0] OpenGL game tutorial in C++

                    1 Reply Last reply
                    0
                    • R Rajesh R Subramanian

                      You could read these couple of very good essays: Inside memory allocation[^] Memory damage primer[^] They aren't particularly explaining how the OS reclaims the resources after a process exits, but nevertheless they make a great read.

                      It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.

                      V Offline
                      V Offline
                      vipin_nvk
                      wrote on last edited by
                      #10

                      Thanx Rajesh

                      R 1 Reply Last reply
                      0
                      • V vipin_nvk

                        Thanx Rajesh

                        R Offline
                        R Offline
                        Rajesh R Subramanian
                        wrote on last edited by
                        #11

                        vipin_nvk wrote:

                        Thanx Rajesh

                        Ah, how very refreshing to see a polite member. Have a 5 vote from me. :)

                        It was ever thus, the Neophiles will always rush out and get 'The Latest Thing' at a high price and with all the inherent faults - Dalek Dave.

                        1 Reply Last reply
                        0
                        • V vipin_nvk

                          When process exit, will the memory that's left undeleted be returned to OS? My application is a C++ application.

                          M Offline
                          M Offline
                          Maximilien
                          wrote on last edited by
                          #12

                          Even if the OS will reclaim the memory, it's no excuse not to clean up yourself. M.

                          Watched code never compiles.

                          1 Reply Last reply
                          0
                          • V vipin_nvk

                            When process exit, will the memory that's left undeleted be returned to OS? My application is a C++ application.

                            N Offline
                            N Offline
                            Niklas L
                            wrote on last edited by
                            #13

                            Always clean up your allocated memory. Even though the OS will reclaim the allocated memory, deleting objects (C++) might have important side effects, such as releasing resources in other processes the instance has allocated on construction. This might lead to 'leaks' in other running processes. Also, if you don't properly delete allocated resources, your code will not be reusable in other applications. Cleaning up your own mess is an important part of C++. Clean up.

                            home

                            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