C++ test

Sep 16, 2014 at 10:53am
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 Sep 16, 2014 at 10:54am
Sep 16, 2014 at 11:05am
You have new without delete so that's an obvious memory leak.
Sep 16, 2014 at 1:03pm
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.