Click to See Complete Forum and Search --> : C++ Memory Management: Why does deleting a pointer cause my program to crash?


Yves M
February 13th, 2003, 01:15 PM
Q: Why does deleting a pointer cause my program to crash?


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 (http://www.codeguru.com/forum/member.php?u=85152)]
<br><br>