New (C++) - Releasing Dynamically Allocated Memory

Releasing Dynamically Allocated Memory

Any memory dynamically allocated with new must be released with delete. The delete operator can be used in two ways: one for de-allocating memory allocated to arrays with new and the other for deleting single objects.

int *p_var = new int; delete p_var; p_var = 0; int *p_array = new int; delete p_array; p_array = 0;

Note that the compiler is not required to generate a diagnostic message for using the wrong delete. Furthermore, using the inappropriate deallocator will result in undefined behavior.

Read more about this topic:  New (C++)

Famous quotes containing the word memory:

    Perhaps a man like you can’t realize what it is to have a conscience and no memory at all. Do you imagine it’s pleasant to be ashamed of something you can’t even remember?
    Orson Welles (1915–1985)