之所以在C C内存泄漏++ [英] reason for memory leakage in C C++

查看:103
本文介绍了之所以在C C内存泄漏++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是什么在C C的原因,内存泄露++
(除通常的分配内存,却忘了释放它)

what are the reasons for memory leakage in C C++ (except the usual allocating memory and forget to deallocate it)

推荐答案

如果一个异常被分配与释放之间的调高,则会产生内存泄漏。

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;
}

每个时间 F1 终止与异常,4个字节泄露(假设 INT 为4个字节)。

Each time f1 terminates with an exception, 4 bytes are leaked (assuming int is 4 byte).

这篇关于之所以在C C内存泄漏++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆