I am using online IDE to test a memory leak for a simple C++ program like below:
#include <iostream>
using namespace std;
int main()
{
int* array = new int[10]; //memory not freed, so should report memory leak
return 0;
}
I am using geeksforgeeks or codechef(gcc 6.3). I read about the memory leak detection, and found 2 ideas like below:
1.
void* operator new(size_t size, int line)
{
printf("Allocate %u bytes on line %d\n", size, line);
return operator new(size);
}
- something about
DEBUG_NEW new (__FILE__, __LINE__)
while debug_new says it only works with MFC. I don't know how to use the 1st option either. Can somebody please help me in pointing out how exactly the memory leak can be discovered in C++ programs on windows/linux?
Comments
Post a Comment