C++ test

Is memory leak in this situation ?

This was a C++ test.
I said that it is memory leak.
I wrote code then I debugged it.
Visual Studio does not report memory leak.


1
2
3
4
5
6
7
8
9
10
11
12
13
void MyFunction( int *x )
{
	x = new int(1);
	*x = 12;
}

int main ()
{
	int *var1 = new int(3);
	MyFunction( var1 );
        return 0;
}
Last edited on
You have new without delete so that's an obvious memory leak.
Visual Studio does not report memory leak.

It's likely that VS uses some heuristic method to spot leaks and this program is just to small to pass it's threshold to register. I wonder if you put Lines 8 and 9 in a for loop and run it a few hundred times, does it find a leak then?
Topic archived. No new replies allowed.