From the discussion started here, I’d like to know whether the following code has a memory leak:
int main()
{
new int();
//or
int* x = new int();
return 0;
}
I know the memory is reclaimed by the OS, but is it a leak anyway? I believe it is.
What defines a memory leak? I could only find one reference in the standard, and it wasn’t very helpful.
EDIT: I don’t want to start a debate – “I think that…” is not the kind of answer I’m looking for. I’m mostly interested in sources – what C++ books or websites or whatever have to say about it.
Second case is not a memory leak.
It is not a leak because you still have an pointer to the memory that was allocated.
To define a memory leak I would like to stick to definition which most of memory analysis tools like valgrind use: