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. delete [] pCharPointer

delete [] pCharPointer

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebuggingquestionannouncement
4 Posts 4 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.
  • U Offline
    U Offline
    utkarsharma
    wrote on last edited by
    #1

    I am face'g proble in the DLL. when I work in Debug mode the code work fine /////--code is--////// char* pCharPointer = new char[intLength]; // //some code // pCharPointer = NULL; delete [] pCharPointer; /////////// But give error in release mode..... ////////////////////////////////////////////////////////// If I change the code to //////--code---///// char* pCharPointer = new char[intLength]; // //some code // //----pCharPointer = NULL; delete [] pCharPointer; /////////// it work's fine in release mode but give error in the debug mode... It will be a big help if some body can clear WHY???? utkarsh sharma "Not everything that counts can be counted, and not everything that can be counted counts."

    M J J 3 Replies Last reply
    0
    • U utkarsharma

      I am face'g proble in the DLL. when I work in Debug mode the code work fine /////--code is--////// char* pCharPointer = new char[intLength]; // //some code // pCharPointer = NULL; delete [] pCharPointer; /////////// But give error in release mode..... ////////////////////////////////////////////////////////// If I change the code to //////--code---///// char* pCharPointer = new char[intLength]; // //some code // //----pCharPointer = NULL; delete [] pCharPointer; /////////// it work's fine in release mode but give error in the debug mode... It will be a big help if some body can clear WHY???? utkarsh sharma "Not everything that counts can be counted, and not everything that can be counted counts."

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      The first snippet is just wrong - you're overwriting the actual pointer to the memory block, which causes delete[] to simply do nothing in release mode. There's probably an assert in debug mode to tell you that you're trying to delete a null pointer. If your debug mode is telling you about a problem, you should probably listen. Release mode doesn't do as much checking. Could you be corrupting this pointer somehow? It would help if you posted the error message(s).

      1 Reply Last reply
      0
      • U utkarsharma

        I am face'g proble in the DLL. when I work in Debug mode the code work fine /////--code is--////// char* pCharPointer = new char[intLength]; // //some code // pCharPointer = NULL; delete [] pCharPointer; /////////// But give error in release mode..... ////////////////////////////////////////////////////////// If I change the code to //////--code---///// char* pCharPointer = new char[intLength]; // //some code // //----pCharPointer = NULL; delete [] pCharPointer; /////////// it work's fine in release mode but give error in the debug mode... It will be a big help if some body can clear WHY???? utkarsh sharma "Not everything that counts can be counted, and not everything that can be counted counts."

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        I wish to elaborate on what mike said.

        char* pCharPointer = new char[intLength]; // pCharPointer now contians an address like 0x50FC3456

        pCharPointer = NULL; // pCharPointer now contians 0x00000000

        delete [] pCharPointer; // does nothing and is still a valid call

        char* pCharPointer = new char[intLength]; // pCharPointer now contians an address like 0x50FC3456

        delete [] pCharPointer; // frees/releases memory
        delete [] pCharPointer; // error - already free
        pCharPointer = NULL; // pCharPointer now contians 0x00000000
        delete [] pCharPointer; // does nothing and is still a valid call

        INTP

        1 Reply Last reply
        0
        • U utkarsharma

          I am face'g proble in the DLL. when I work in Debug mode the code work fine /////--code is--////// char* pCharPointer = new char[intLength]; // //some code // pCharPointer = NULL; delete [] pCharPointer; /////////// But give error in release mode..... ////////////////////////////////////////////////////////// If I change the code to //////--code---///// char* pCharPointer = new char[intLength]; // //some code // //----pCharPointer = NULL; delete [] pCharPointer; /////////// it work's fine in release mode but give error in the debug mode... It will be a big help if some body can clear WHY???? utkarsh sharma "Not everything that counts can be counted, and not everything that can be counted counts."

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          pCharPointer = NULL;
          delete [] pCharPointer;

          Sir, are you blind? That if anything ought to raise suspicions. :) -- If there was a problem, Yo, I'll solve it! Check out the hook while my DJ revolves it.

          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