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. mem allocation in console app

mem allocation in console app

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
9 Posts 5 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.
  • 9 Offline
    9 Offline
    9ine
    wrote on last edited by
    #1

    if there is allocation of some memory in console application and then it quits without deallocation (that is mem leak). Will windows free this leak itself after console application is terminated?

    9ine

    T J 2 Replies Last reply
    0
    • 9 9ine

      if there is allocation of some memory in console application and then it quits without deallocation (that is mem leak). Will windows free this leak itself after console application is terminated?

      9ine

      J Offline
      J Offline
      Jonathan Darka
      wrote on last edited by
      #2

      yes, but you should really fix the mem leak first :)


      Darka [Xanya] "When you're taught to love everyone, to love your enemies, then what value does that place on love?"

      1 Reply Last reply
      0
      • 9 9ine

        if there is allocation of some memory in console application and then it quits without deallocation (that is mem leak). Will windows free this leak itself after console application is terminated?

        9ine

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        it is supposed to, but it might fail sometimes in tracking such memory... so, good programming practices remain the best : you allocate some memory ; then, YOU delete it before exiting the program.


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        9 1 Reply Last reply
        0
        • T toxcct

          it is supposed to, but it might fail sometimes in tracking such memory... so, good programming practices remain the best : you allocate some memory ; then, YOU delete it before exiting the program.


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          9 Offline
          9 Offline
          9ine
          wrote on last edited by
          #4

          yeah, I know, I know. But this should be some kind of advantige for console app if do a lot mem allocation, files handles, then you can allow yourself to get rid of that collection of all those resources and garbagging your code. Its not the case when you write some class to be perfect without any leaks or handles.

          9ine

          T 1 Reply Last reply
          0
          • 9 9ine

            yeah, I know, I know. But this should be some kind of advantige for console app if do a lot mem allocation, files handles, then you can allow yourself to get rid of that collection of all those resources and garbagging your code. Its not the case when you write some class to be perfect without any leaks or handles.

            9ine

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            :~ why because it is a console application that it couldn't be OOP ? and what is that way of thinking that console applications should be less well designed than graphical apps... :confused: really, i don't understand your point of view.


            TOXCCT >>> GEII power

            [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

            9 1 Reply Last reply
            0
            • T toxcct

              :~ why because it is a console application that it couldn't be OOP ? and what is that way of thinking that console applications should be less well designed than graphical apps... :confused: really, i don't understand your point of view.


              TOXCCT >>> GEII power

              [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

              9 Offline
              9 Offline
              9ine
              wrote on last edited by
              #6

              Whats the point, writing additional mem free routines to get rid of allocated ones, as it will be deallocated after console is terminated. It is very well designed and quite large but without deallocation. How can it be OOP one?

              9ine

              Z G 2 Replies Last reply
              0
              • 9 9ine

                Whats the point, writing additional mem free routines to get rid of allocated ones, as it will be deallocated after console is terminated. It is very well designed and quite large but without deallocation. How can it be OOP one?

                9ine

                Z Offline
                Z Offline
                Zac Howland
                wrote on last edited by
                #7

                9ine wrote:

                Whats the point, writing additional mem free routines to get rid of allocated ones, as it will be deallocated after console is terminated. It is very well designed and quite large but without deallocation.

                This makes no sense. Technically, heap memory will be reclaimed by the OS after the program terminates, but if you fail to free it yourself when you are done with it, then your program will slowly (or not so slowly) eat up more and more memory while it is executing (assuming you are allocating based on some set of events -- and if you are not, chances are that data would be better served on the stack anyway). As far as file handles (and pretty much any kernel object), they will NOT be reclaimed when your program exits. This means that if you open a file and then quit, you may need to restart your computer before you can reopen that file (NOT GOOD!). The point is, if you allocate memory, you should free it. If you don't, do not submit that code as an assignment nor as production code for any company ... it will be rejected as incomplete.

                If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                9 1 Reply Last reply
                0
                • 9 9ine

                  Whats the point, writing additional mem free routines to get rid of allocated ones, as it will be deallocated after console is terminated. It is very well designed and quite large but without deallocation. How can it be OOP one?

                  9ine

                  G Offline
                  G Offline
                  Gary R Wheeler
                  wrote on last edited by
                  #8

                  9ine wrote:

                  It is very well designed and quite large

                  It is not well designed if it fails to clean up after itself. True, the operating system will clean up most resources allocated by your program after it exits, even when you don't free them yourself. The problem is, it may not free all of them. There are resources in Windows that are not freed automatically when a program exits. This means that your program could leave behind resource allocations that can never be freed without a restart. Dangling allocations could also cause your application to fail the next time you run it. A resource you allocated previously and did not free is no longer available. The other problem is that, while your program is running, it continually consumes more and more resources. If you don't free them as soon as you are done using them, they are a waste. Those resources aren't available for use by other applications or the operating system.


                  Software Zen: delete this;

                  Fold With Us![^]

                  1 Reply Last reply
                  0
                  • Z Zac Howland

                    9ine wrote:

                    Whats the point, writing additional mem free routines to get rid of allocated ones, as it will be deallocated after console is terminated. It is very well designed and quite large but without deallocation.

                    This makes no sense. Technically, heap memory will be reclaimed by the OS after the program terminates, but if you fail to free it yourself when you are done with it, then your program will slowly (or not so slowly) eat up more and more memory while it is executing (assuming you are allocating based on some set of events -- and if you are not, chances are that data would be better served on the stack anyway). As far as file handles (and pretty much any kernel object), they will NOT be reclaimed when your program exits. This means that if you open a file and then quit, you may need to restart your computer before you can reopen that file (NOT GOOD!). The point is, if you allocate memory, you should free it. If you don't, do not submit that code as an assignment nor as production code for any company ... it will be rejected as incomplete.

                    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                    9 Offline
                    9 Offline
                    9ine
                    wrote on last edited by
                    #9

                    oh, kernel objects memory leaks are my favorite ones! never clean them after myself whats the point allocation during the start of the console for say 1000 strings of 256 bytes long and then leaving the program without deleting them.

                    9ine

                    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