delete Error

This is a discussion on delete Error within the C++ Programming forums, part of the General Programming Boards category; In a base class, i declare an integer pointer, int* cellDesc; Then, in the constructor of a derived class... cellDesc ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    17

    delete Error

    In a base class, i declare an integer pointer,

    int* cellDesc;

    Then, in the constructor of a derived class...

    cellDesc = new int[somenumber];

    and in the destructor of that derived class...

    delete [] cellDesc;

    Is there anything wrong with this code??? At the delete line I get;

    Debug Error!
    Program : ...
    DAMAGE: after normal block (#81) 0x00791710


    The numbers dont matter, i think; they change every time.
    Does anyone have any ideas?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    delete cellDesc; your int is still a pointer even after you allocate memory for it.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    delete cellDesc; your int is still a pointer even after you allocate memory for it.

    Yeah, it's still a pointer to an int, but since it points to an array, it must have the [] in it like phatslug has done.

    Are you sure you're not deleting it twice for some reason?! EG. is the base class destroying memory too?

    You might have to give us a bit more code to figure out what's wrong.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  4. #4
    Registered User
    Join Date
    Jun 2002
    Posts
    17
    hmm... I couldnt readily give u more code without pasting a coupla hundred lines. Ahh.. I probably screw up the heap somewhere else in the program and this is how it manifests itself.

    Also I added

    if (cellDesc != NULL)
    {
    delete [] cellDesc;
    cellDesc = NULL;
    }

    .. incase I was deleting it twice and now beside the error message it also dumps in the debug window

    memory check error at 0x00791B28 = 0x00, should be 0xFD.
    memory check error at 0x00791B29 = 0x00, should be 0xFD.
    memory check error at 0x00791B2A = 0x00, should be 0xFD.
    memory check error at 0x00791B2B = 0x00, should be 0xFD.

    The address of cellDesc, in this case is 00791B10.

    Well.. I'm stumped.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    maybe your pointer is going out of scope. i had this problem once, dunno exactly how i fixed it ... SilentStrike helped me i think.

  6. #6
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    here are two possibilites!

    one you have a mamory leak/allocation bug somewhere else in the code(most likely, check this first),
    or its a freak compiler error(unlikely but possible), i've had this with using new before in less than ten lines and only one allocation...

    use malloc() and free() and see if it still fails...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 01:17 AM
  2. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM

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