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. Does it have some memory leak?

Does it have some memory leak?

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

    char chr[100]; strcpy( chr, "oh,my god,give u a long word" ); chr[5] = '\0'; Joise is a C++ fun!

    D B 2 Replies Last reply
    0
    • J Joise

      char chr[100]; strcpy( chr, "oh,my god,give u a long word" ); chr[5] = '\0'; Joise is a C++ fun!

      D Offline
      D Offline
      Dave Bryant
      wrote on last edited by
      #2

      No - the array has been allocated on the stack, so there is no need to delete it (in fact deleting it is an error). Dave http://www.cloudsofheaven.org

      J 1 Reply Last reply
      0
      • J Joise

        char chr[100]; strcpy( chr, "oh,my god,give u a long word" ); chr[5] = '\0'; Joise is a C++ fun!

        B Offline
        B Offline
        Brian Shifrin
        wrote on last edited by
        #3

        No it is not possible to have a leak, char[100] allocate memory on the stack, when you exit function memory will be simply popped. In fact if you had allocated memory with: a = malloc(100); a[1] = NULL; free(a); you would not be leaking, de-allocator knows what size you allocated.

        J 1 Reply Last reply
        0
        • D Dave Bryant

          No - the array has been allocated on the stack, so there is no need to delete it (in fact deleting it is an error). Dave http://www.cloudsofheaven.org

          J Offline
          J Offline
          Joise
          wrote on last edited by
          #4

          thx so much,i know it now Joise is a C++ fun!

          1 Reply Last reply
          0
          • B Brian Shifrin

            No it is not possible to have a leak, char[100] allocate memory on the stack, when you exit function memory will be simply popped. In fact if you had allocated memory with: a = malloc(100); a[1] = NULL; free(a); you would not be leaking, de-allocator knows what size you allocated.

            J Offline
            J Offline
            Joise
            wrote on last edited by
            #5

            thx,i got it Joise is a C++ fun!

            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