Memory question

Started by
1 comment, last by SiCrane 15 years, 10 months ago
Alot of things (expecialy the older stuff) return "const char*" . eg "const char* LastError()" Seeing as these are const so I can't edit them does this mean that they will go out of scope and get deleted for me or do I this need to delete them myself?
Advertisement
You delete only and exactly what you new.

If you didn't allocate it, you don't delete it.

This applies to implementation of functions as well, for example, Foo * createFoo() may require you to call deleteFoo(Foo * foo), if that particular library requires you to do so.
Read the documentation for the function in question. Ex: strdup() returns a memory block that you need to call free() on. SDL_GetError() returns a string that you don't need to clean up.

This topic is closed to new replies.

Advertisement