what are the causes of memory leaks in c

Solutions on MaxInterview for what are the causes of memory leaks in c by the best coders in the world

showing results for - "what are the causes of memory leaks in c"
Ricardo
06 Feb 2018
1
2
3//If an exception is raised between allocation and deallocation, memory leak will occur.
4
5void f1() {
6    int* ptr = new int;
7
8    // do something which may throw an exception
9
10    // we never get here if an exception is thrown
11    delete ptr;
12}