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. Memory Leak

Memory Leak

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresperformance
8 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.
  • R Offline
    R Offline
    rr_ramesh71
    wrote on last edited by
    #1

    I have a static function in that I have some array members, that function will be called from so many places, I want to know that when ever the process of the function is over means all the member variables will be get released from memory or will Occupy the space.

    P S C 3 Replies Last reply
    0
    • R rr_ramesh71

      I have a static function in that I have some array members, that function will be called from so many places, I want to know that when ever the process of the function is over means all the member variables will be get released from memory or will Occupy the space.

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      rr_ramesh71 wrote:

      I have some array member

      What kind of array it is ?

      R 1 Reply Last reply
      0
      • R rr_ramesh71

        I have a static function in that I have some array members, that function will be called from so many places, I want to know that when ever the process of the function is over means all the member variables will be get released from memory or will Occupy the space.

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

        How are the arrays declared? If they're declared as local variables (as shown with localArray below), they will definitely be cleared up, as they're allocated space on the stack, which is tidied up when the function exits.

        double SomeFunction(int x)
        {
        double localArray[] = { 1.0, 2.0, 3.0, 4.0 };
        const size_t localArraySize = sizeof localArray / sizeof localArray[0];
        return x<localArraySize?localArray[x]:-1.0;
        }

        1 Reply Last reply
        0
        • R rr_ramesh71

          I have a static function in that I have some array members, that function will be called from so many places, I want to know that when ever the process of the function is over means all the member variables will be get released from memory or will Occupy the space.

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

          The only thing you have to take care in this case, is that if you are allocating memory with new (or new[]), then you should delete it with delete (or delete[]). For the rest, the memory will be automatically released.

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

          C 1 Reply Last reply
          0
          • P prasad_som

            rr_ramesh71 wrote:

            I have some array member

            What kind of array it is ?

            R Offline
            R Offline
            rr_ramesh71
            wrote on last edited by
            #5

            char lbuffer[5000]; // will this array get released after the function over
            sprintf(lbuffer,"Stock in List [%s] Quantiry %d", SymbolList,qty);

            but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed

            C P 2 Replies Last reply
            0
            • C Cedric Moonen

              The only thing you have to take care in this case, is that if you are allocating memory with new (or new[]), then you should delete it with delete (or delete[]). For the rest, the memory will be automatically released.

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

              C Offline
              C Offline
              Code o mat
              wrote on last edited by
              #6

              Also don't forget malloc and free (I know, i know, don't use malloc and free in C++ but they CAN be used), and maybe GlobalAlloc and GlobalFree (or LocalAlloc and LocalFree but as far as i know those are no longer different from their Global counterparts)

              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

              1 Reply Last reply
              0
              • R rr_ramesh71

                char lbuffer[5000]; // will this array get released after the function over
                sprintf(lbuffer,"Stock in List [%s] Quantiry %d", SymbolList,qty);

                but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed

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

                Yes the buffer will be released.

                rr_ramesh71 wrote:

                but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed

                How do you check that ? Are you using some tools to verify that information ?

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

                1 Reply Last reply
                0
                • R rr_ramesh71

                  char lbuffer[5000]; // will this array get released after the function over
                  sprintf(lbuffer,"Stock in List [%s] Quantiry %d", SymbolList,qty);

                  but according to me memory is keeps on increasing when ever we call the function it is not reducing after it is completed

                  P Offline
                  P Offline
                  prasad_som
                  wrote on last edited by
                  #8

                  rr_ramesh71 wrote:

                  // will this array get released after the function over

                  Yes, You don't need to worry about memory, as its been allocated on stack.

                  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