什么会引起泄漏? [英] What can cause a leak?

查看:119
本文介绍了什么会引起泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道一个简洁地列出每种可能的内存泄漏原因的源吗?

到目前为止,我知道这一点:

1.拨打新电话,但不拨打delete
2.将新值重新分配给已经具有新obj
的指针 2.具有一个没有虚拟析构函数的基类
3.具有带有智能指针的循环引用

还有什么?随时编辑我的措辞并使此列表更好.谢谢.

Does anybody know a source that lists, succinctly, every possible cause of memory leaks?

So far I know this:

1. Call new without calling delete
2. Re-assign a new value to a pointer that already had a new obj
2. Have a base class without a virtual destructor
3. Have a cyclic reference with smart pointers

What else? Feel free to edit my wording and make this list better. Thanks.

推荐答案

就是这样.当您丢失"对内存的引用而不清理内存时,就会泄漏.因此,将指针设置为null而不删除该对象将导致内存泄漏.在方法范围内创建对象而不进行清理是内存泄漏,因为当值超出范围时,该值会丢失.在所有情况下,泄漏都是因为您分配了内存,并且在不再需要它时无法清理它.
That''s really about it. You leak when you ''lose'' a reference to memory without cleaning it up. So, setting a pointer to null, without deleting the object, is a memory leak. Creating an object in the scope of the method and not cleaning it up, is a memory leak, because the value is lost when it goes out of scope. In all cases, you leak because you allocated memory and you lose the ability to clean it up when it is no longer needed.


这篇关于什么会引起泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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