<bdo id='Hytku'></bdo><ul id='Hytku'></ul>
  • <small id='Hytku'></small><noframes id='Hytku'>

      <i id='Hytku'><tr id='Hytku'><dt id='Hytku'><q id='Hytku'><span id='Hytku'><b id='Hytku'><form id='Hytku'><ins id='Hytku'></ins><ul id='Hytku'></ul><sub id='Hytku'></sub></form><legend id='Hytku'></legend><bdo id='Hytku'><pre id='Hytku'><center id='Hytku'></center></pre></bdo></b><th id='Hytku'></th></span></q></dt></tr></i><div id='Hytku'><tfoot id='Hytku'></tfoot><dl id='Hytku'><fieldset id='Hytku'></fieldset></dl></div>

      <tfoot id='Hytku'></tfoot>

      <legend id='Hytku'><style id='Hytku'><dir id='Hytku'><q id='Hytku'></q></dir></style></legend>
      1. 对动态分配的对象调用 delete 是否总是内存泄漏?

        Is not calling delete on a dynamically allocated object always a memory leak?(对动态分配的对象调用 delete 是否总是内存泄漏?)

        1. <legend id='gH5iu'><style id='gH5iu'><dir id='gH5iu'><q id='gH5iu'></q></dir></style></legend>

          • <tfoot id='gH5iu'></tfoot>
            • <bdo id='gH5iu'></bdo><ul id='gH5iu'></ul>

                <i id='gH5iu'><tr id='gH5iu'><dt id='gH5iu'><q id='gH5iu'><span id='gH5iu'><b id='gH5iu'><form id='gH5iu'><ins id='gH5iu'></ins><ul id='gH5iu'></ul><sub id='gH5iu'></sub></form><legend id='gH5iu'></legend><bdo id='gH5iu'><pre id='gH5iu'><center id='gH5iu'></center></pre></bdo></b><th id='gH5iu'></th></span></q></dt></tr></i><div id='gH5iu'><tfoot id='gH5iu'></tfoot><dl id='gH5iu'><fieldset id='gH5iu'></fieldset></dl></div>

                  <small id='gH5iu'></small><noframes id='gH5iu'>

                    <tbody id='gH5iu'></tbody>
                  本文介绍了对动态分配的对象调用 delete 是否总是内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  从讨论开始这里,我想知道以下代码是否存在内存泄漏:>

                  From the discussion started here, I'd like to know whether the following code has a memory leak:

                  int main()
                  {
                     new int();
                     //or
                     int* x = new int();
                     return 0;
                  }
                  

                  我知道内存已被操作系统回收,但这是否是泄漏?我相信是的.

                  I know the memory is reclaimed by the OS, but is it a leak anyway? I believe it is.

                  内存泄漏的定义是什么?我只能在标准中找到一个参考,而且不是很有帮助.

                  What defines a memory leak? I could only find one reference in the standard, and it wasn't very helpful.

                  我不想开始辩论——我认为……"不是我想要的那种答案.我最感兴趣的是来源 - 什么 C++ 书籍或网站或任何关于它的内容.

                  推荐答案

                  第二种情况不是内存泄漏.
                  这不是泄漏,因为您仍然有一个指向分配的内存的指针.
                  为了定义内存泄漏,我想坚持大多数内存分析工具(如 valgrind)使用的定义:

                  Second case is not a memory leak.
                  It is not a leak because you still have an pointer to the memory that was allocated.
                  To define a memory leak I would like to stick to definition which most of memory analysis tools like valgrind use:

                  内存已分配,随后无法释放,因为程序不再有任何指向已分配内存块的指针.

                  Memory was allocated and cannot be subsequently freed because the program no longer has any pointers to the allocated memory block.

                  这篇关于对动态分配的对象调用 delete 是否总是内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                      <tbody id='9ceLK'></tbody>

                  1. <i id='9ceLK'><tr id='9ceLK'><dt id='9ceLK'><q id='9ceLK'><span id='9ceLK'><b id='9ceLK'><form id='9ceLK'><ins id='9ceLK'></ins><ul id='9ceLK'></ul><sub id='9ceLK'></sub></form><legend id='9ceLK'></legend><bdo id='9ceLK'><pre id='9ceLK'><center id='9ceLK'></center></pre></bdo></b><th id='9ceLK'></th></span></q></dt></tr></i><div id='9ceLK'><tfoot id='9ceLK'></tfoot><dl id='9ceLK'><fieldset id='9ceLK'></fieldset></dl></div>

                      <small id='9ceLK'></small><noframes id='9ceLK'>

                        <bdo id='9ceLK'></bdo><ul id='9ceLK'></ul>
                        <tfoot id='9ceLK'></tfoot>
                          <legend id='9ceLK'><style id='9ceLK'><dir id='9ceLK'><q id='9ceLK'></q></dir></style></legend>