Do I need to delete[] this?

This is a discussion on Do I need to delete[] this? within the C++ Programming forums, part of the General Programming Boards category; lol ok ok, no delete I get the point! (btw, thanks everyone else for your confusing goto stuff... I'll figure ...

  1. #16
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    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
    Posts
    856
    Just one more point about why not to do that.

    When you have any static string in your program
    ie:
    #define STR_MSG "This is a static string"
    or
    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.

Page 2 of 2 FirstFirst 12
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, 11: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, 08:45 AM
  5. delete and delete[]
    By Hunter2 in forum C++ Programming
    Replies: 13
    Last Post: 06-26-2003, 05:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21