• !! vc C++ VS2017检查内存泄漏具体到某一行代码


    ref: 

    VS2017的C++开发心得(十一)调试——内存溢出和内存泄漏(上)

    https://blog.csdn.net/luoyu510183/article/details/84728664

    VS的调试功能非常强大,一方面是覆盖面很广可以调试本地程序,也可以调试远程的Linux服务器程序。另一方面是内容很丰富,基于汇编调试之上,可以查看内存信息,线程堆栈,甚至GPU、CPU的占用情况,还有DX12的图形调试以及NVIDIA的Nsight的CUDA调试。基本满足你从开发到优化到debug到发布的所有需求。

    本章介绍VS下的本地程序的调试方法。

    本地程序的调试主要分为两种,一种是主动调试,一种是被动调试。主动调试:即编译并运行,就是“本地Windows调试器”。被动调试:这个需求比较灵活,一般是程序已经发布了release版本,直接双击exe运行而不依赖于VS了。exe运行过程中可能会报错,可能状态异常,这时候我们需要通过VS去链接到这个exe进程进行调试。
    ————————————————
    版权声明:本文为CSDN博主「Mr_L_Y」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/luoyu510183/article/details/84728664

    C++ VS2017检查内存泄漏具体到某一行代码

    https://www.freesion.com/article/1508677081/

        VLD工具可以用来检查VS C++程序的内存泄露。

           VLD官网:https://kinddragon.github.io/vld/

           官网不方便下载的,可以用我的链接:https://pan.baidu.com/s/1-SiP9bYCfk67aUmKIOUwpQ   提取码:dvaw

           下载安装VLD后会有 include, lib, bin,vlc.ini等文件。把include, lib, bin添加到程序中,如果是C++老鸟,应该不难。然后在代码中添加头文件 #include"vld.h" 即可, 例如下面的代码

    #include <iostream>
    #include "vld.h"
     
    #pragma comment(lib, "vld.lib")
     
    int main()
    {
        int *arr = new int[10];
     
        return 0;
    }

            数组arr没有被delete, 进程结束后,仍然有40个字节的内存片段泄露。把VLD bin目录除了dbghelp.dll的文件复制到程序可执行目录,去你的VS2017安装路径找到dbghelp.dll,例如我的路径:C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\Extensions\Cpp\x64,把该路径的dbghelp.dll复制到程序可执行目录。

              运行后,经过VLD检测,在VS的输出

           直接定位出哪一行除了内存泄漏。该内容也可以写到文件中,在做压力测试时,可以比较直观的查看。把安装目录vld.ini复制到程序exe所在目录,查看ReportFile和ReportTo的配置,这英语不难,可以自行设置,如下:

    ; Sets the report file destination, if reporting to file is enabled. A relative
    ; path may be specified and is considered relative to the process' working
    ; directory.
    ;
    ;   Valid Values: Any valid path and filename.
    ;   Default: .\memory_leak_report.txt
    ;
    ReportFile = .\memory_leak123.txt

    ; Sets the report destination to either a file, the debugger, or both. If
    ; reporting to file is enabled, the report is sent to the file specified by the
    ; ReportFile option.
    ;
    ;   Valid Values: debugger, file, both
    ;   Default: debugger
    ;
    ReportTo = file

         测试时可以设为绝对路径,我这里设置的是相对路径,会跑到代码目录,如下图:

    版权声明:本文为yao_hou原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
    本文链接:https://blog.csdn.net/yao_hou/article/details/106150527
  • 相关阅读:
    Pandas对于CSV的简单操作
    前端之BOM和DOM
    前端之JavaScript
    前端之CSS初识
    定时ping取返回值并绘图
    etree不存在解决方法
    内置方法练习(一)
    pip使用
    python变量、变量属性
    python 爬取段子网段子写入文件
  • 原文地址:https://www.cnblogs.com/carl2380/p/15905105.html
Copyright © 2020-2023  润新知