Thread: delete[] without new[]?

  1. #1
    Chad Johnson
    Join Date
    May 2004
    Posts
    154

    delete[] without new[]?

    Is there ever a case when I should use delete[] when I have not used new[] to allocate memory?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    no..
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If osmeone else does the new[] for you?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    82
    Could he mean if there is a new[] inside a conditional? At which point this might happen:
    Code:
    int* ptr_var = 0;
    
    //... possibility of ptr_var = new int[SIZE]
    
    delete [] ptr_var;

  5. #5
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    I mean that or anything that you can think of.

    Can you explain what you mean by "new[] inside a conditional"?

  6. #6
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    Quote Originally Posted by ChadJohnson
    I mean that or anything that you can think of.

    Can you explain what you mean by "new[] inside a conditional"?
    Whether the allocation was based on a condition. But that still means the delete has a corresponding new...

  7. #7
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Well, just like delete, you can safely delete[] on a NULL pointer.
    Code:
    int main(void)
    {
    	int* a = NULL;
    	delete[] a;
    	return 0;
    }
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. delete[] problem with release config...
    By mikahell in forum C++ Programming
    Replies: 8
    Last Post: 08-21-2006, 10:37 AM
  2. Delete[] Error...
    By XSquared in forum C++ Programming
    Replies: 16
    Last Post: 08-06-2005, 12:29 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