c++ check memory leaks
xxxxxxxxxx
// Add this line in the beginning of the main function:
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
xxxxxxxxxx
// Program with memory leak
#include <bits/stdc++.h>
using namespace std;
// function with memory leak
void func_to_show_mem_leak()
{
int* ptr = new int(5);
// body
// return without deallocating ptr
return;
}
// driver code
int main()
{
// Call the function
// to get the memory leak
func_to_show_mem_leak();
return 0;
}