Can't delete memory

This is a discussion on Can't delete memory within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by jcafaro10 Nothing can be accessing the stack after I delete it because I call exit(0) so perhaps ...

  1. #46
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    Quote Originally Posted by jcafaro10 View Post
    Nothing can be accessing the stack after I delete it because I call exit(0) so perhaps it's something else.
    But it IS accessing the stack. The stack contains the return address from when you called delete. That return address is accessed (on the stack you just deleted) when the call to delete returns.

    It's certainly wrong, but I'm not sure it's the cause of your crash.

    At any rate, the "cleanup thread" should probably not be one of your threads, but actually the main program thread, running on the "normal" stack.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  2. #47
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by brewbuck View Post
    But it IS accessing the stack. The stack contains the return address from when you called delete. That return address is accessed (on the stack you just deleted) when the call to delete returns.

    It's certainly wrong, but I'm not sure it's the cause of your crash.

    At any rate, the "cleanup thread" should probably not be one of your threads, but actually the main program thread, running on the "normal" stack.
    Or at the very least, you should not be trying to delete the stack for the cleanup thread until you get back to your main thread.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  2. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 12:57 AM
  3. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM
  4. Memory handler
    By Dr. Bebop in forum C Programming
    Replies: 7
    Last Post: 09-15-2002, 04:14 PM
  5. multiple indirection...
    By doubleanti in forum C++ Programming
    Replies: 7
    Last Post: 08-31-2001, 10:56 AM

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