Thread: Do I need to delete[] this?

  1. #16
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    lol ok ok, no delete I get the point! (btw, thanks everyone else for your confusing goto stuff... I'll figure it out later )
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #17
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Just one more point about why not to do that.

    When you have any static string in your program
    #define STR_MSG "This is a static string"
    const char *STR_MSG = "This is a static string";
    basically any char array that is literally defined in a source file (with quotes), that array is allocated in static memory when compiled.

    When you call 'delete []' you are instructing the program to go to the address of the pointer you specify (which should be in heap memory) and free it for the OS. The way a 'delete []' works is it looks to the previous memory location of the pointer to see how many bytes were allocated with 'new' and deletes that size beginning at the address of the pointer. As you can see, this will cause innumerable problems because not only are you trying to delete data from static memory, but you are deleting an unknown number of bytes from there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. delete[]
    By R.Stiltskin in forum C++ Programming
    Replies: 23
    Last Post: 11-24-2008, 05:26 PM
  2. delete[] problem with release config...
    By mikahell in forum C++ Programming
    Replies: 8
    Last Post: 08-21-2006, 10:37 AM
  3. delete[] or delete?
    By X PaYnE X in forum C++ Programming
    Replies: 7
    Last Post: 03-30-2005, 03:16 PM
  4. Memory issue with new[] and delete[]
    By Zarkhalar in forum C++ Programming
    Replies: 24
    Last Post: 08-07-2004, 07:45 AM
  5. delete and delete[]
    By Hunter2 in forum C++ Programming
    Replies: 13
    Last Post: 06-26-2003, 04:40 AM