3

I am newbie to VSCode. Currently I would like to debug the memory leakage issue in the program. Therefore after searching the internet, I found that _CrtDumpMemoryLeaks() can be used to debug which line of code cause the memory leak issue. Therefore I wrote a C program in VSCode.

#include<stdio.h>
#include<stdlib.h>
#include <crtdbg.h>
int main (int argc, char* argv[])
{
    int* offset_x = malloc(sizeof(int));
    int* offset_y = malloc(sizeof(int));
    if (offset_x==NULL || offset_y == NULL)
    {
         return 1;
     }
     *offset_x =10;
     *offset_y = 20;
     printf("%d",offset_x);
     free(offset_x);
     _CrtDumpMemoryLeaks();
     return 0;
}

After running the program in VSCode, I got an error of

crtdbg.h: No such file or directory

in VSCode. I found crtdbg.h library is already inside the "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt".

In the internet most of the c programs are run in visual studio community instead of VSCode to debug the memory leak issue.

Therefore, I would like to know if I want to use VSCode to debug the memory leak problem, can I use _CrtDumpMemoryLeaks() and how can I solve the problem of "crtdbg.h: No such file or directory" in VSCode as I think I already had crtdbg.h in "C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt" and I don't know why VSCode said no such file or directory.

Thank you.

Susan
  • 431
  • 1
  • 4
  • 16
  • How about using [Visual Leak Detector](https://stackoverflow.com/questions/58439722/how-to-install-visual-leak-detector-vld-on-visual-studio-2019) instead? –  Dec 29 '21 at 08:05

0 Answers0