Monday, April 21, 2008

How to dealocete char* str = "something";

char* str = "something";
If you try to delete str you will get exception at _CrtIsValidHeapPointer.

The thing is that you can not dealoce str because you didn't alocated it at all.
And don't wory. You will not get memory leaks. This string is already in memory. When this command is executed str just get pointer to that part of memory.
Compile program, open it (.exe) in some hex editor and search for "something". It's there :))))

No comments: