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

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

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

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

      C++ valgrind 在 hello world 中显示内存泄漏

      c++ valgrind shows memory leak in hello world(C++ valgrind 在 hello world 中显示内存泄漏)
      <tfoot id='dBs9D'></tfoot>
        <tbody id='dBs9D'></tbody>

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

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

              • 本文介绍了C++ valgrind 在 hello world 中显示内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的程序代码是

                #include <iostream>
                
                int main(int argc, const char *argv[])
                {
                  std::cout << "hello world!
                ";
                  return 0;
                }
                

                我用标志编译它

                -Wpedantic -pedantic-errors -std=c++11 -g -Wall -Wextra
                

                在上面运行Valgrind,看到了一些奇怪的东西,这个简单的程序有内存泄漏,valgrind --leak-check=full --show-leak-kinds=all命令的输出是

                Run Valgrind on it and saw something strange, this simple program has memory leak, output of valgrind --leak-check=full --show-leak-kinds=all command is

                ==4492== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
                ==4492==    at 0x4C28C20: malloc (vg_replace_malloc.c:296)
                ==4492==    by 0x4EBF11F: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
                ==4492==    by 0x400E9F9: call_init.part.0 (dl-init.c:78)
                ==4492==    by 0x400EAE2: call_init (dl-init.c:36)
                ==4492==    by 0x400EAE2: _dl_init (dl-init.c:126)
                ==4492==    by 0x40011C9: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)
                

                我的问题是 - 如何找出发生了什么?

                my question is - how to find out what is going on?

                推荐答案

                这是linux系统动态库加载器永远保留的内存.找出发生了什么的方法包括阅读 _dl_init() 函数的代码,例如:此处.另一种选择是使用调试器逐步执行您的程序,您需要在运行之前 break _init 并且可能还使用 disassemblesi,因为 glibc 不能在未优化的情况下构建.

                This is memory reserved forever by linux system dynamic library loader. Ways to find out what's going on include reading code for _dl_init() function, e.g.: here. Another option is to step-through your program with debugger, you'll want to break _init before run and probably also use disassemble and si, as glibc can't be built unoptimized.

                查看讨论这里(可能标记作为重复)

                See discussion here (and probably mark as dup)

                这篇关于C++ valgrind 在 hello world 中显示内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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(使用非平凡的构造函数初始化联合)
                <legend id='1uaJc'><style id='1uaJc'><dir id='1uaJc'><q id='1uaJc'></q></dir></style></legend>

                  <small id='1uaJc'></small><noframes id='1uaJc'>

                  • <tfoot id='1uaJc'></tfoot>

                        <tbody id='1uaJc'></tbody>

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