CS253: Software Development with C++

Spring 2018

Double Delete

See this page as a slide show

CS253 Double Delete

Double Delete

Every call to new must be matched by exactly one delete.

Not zero, and not two. One.

Similarly, every call to new [] must be matched by exactly one delete [].

Zero Delete

If you don’t call delete, then the memory is forgotten. We call this a memory leak.

Sure, the memory will be implicitly freed when the program ends. However, some programs run for a good long time before they end.

Multiple Delete

What happens if you call delete more than once?

float *p = new float[100];
delete[] p;
delete[] p;
free(): double free detected in tcache 2
SIGABRT: Aborted

User: Guest

Check: HTML CSS
Edit History Source

Modified: 2018-04-24T16:51

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building