Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

why exceptions can lead to memory leaks

//If an exception is raised between allocation and deallocation, memory leak will occur.

void f1() {
    int* ptr = new int;

    // do something which may throw an exception

    // we never get here if an exception is thrown
    delete ptr;
}
 
PREVIOUS NEXT
Tagged: #exceptions #lead #memory #leaks
ADD COMMENT
Topic
Name
5+4 =