This feature checks your currently open file for potential issues.
Open any C or C++ file (.c, .cpp).
Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P on Mac).
Type and select C++ Memory Check: Analyze Current File.
Any potential issues found by cppcheck will appear with squiggly lines in your code and will be listed in the Problems panel (Ctrl+Shift+M).
2. Runtime Analysis
This feature configures your project for compilation and debugging with AddressSanitizer to find actual leaks at runtime.
Step A: One-Time Configuration
Open the Command Palette (Ctrl+Shift+P).
Type and select C++ Memory Check: Configure for Runtime Analysis.
This will automatically create or update tasks.json and launch.json inside your project's .vscode folder.
Step B: Running the Analysis
Open the C++ file you want to test (e.g., test.cpp).
Go to the Run and Debug view from the side bar.
From the configuration dropdown at the top, select C++: Run with AddressSanitizer.
Press the green play button (or F5) to start debugging.
Once your program finishes, check the Debug Console panel for a detailed memory leak report from AddressSanitizer.
How It Works
Static Analysis: The extension runs the cppcheck command-line tool on the active file. It uses a custom output template to reliably parse the results and transform them into VS Code Diagnostics.
Runtime Analysis: The extension automates the setup process by:
Creating a build task in tasks.json that compiles your code using g++ with the -g and -fsanitize=address flags.
Creating a launch configuration in launch.json that specifies the instrumented executable and links it to the build task.