CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    C++ Memory Management: Why does deleting a pointer cause my program to crash?

    Q: Why does deleting a pointer cause my program to crash?

    Code:
    char*    a_string = "beware, the end is near!";
    delete[] a_string;
    A: Because the memory that a_string points to was not allocated with new. Only delete memory that was allocated with new. In particular, this string is a constant, so you should not delete it. Also beware that you can not use delete to release memory allocated with malloc.


    FAQ contributed by: [Kevin Hall]


    Last edited by Andreas Masur; July 23rd, 2005 at 01:42 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured