📜  为什么异常会导致内存泄漏 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:58.328000             🧑  作者: Mango

代码示例1
//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;
}