Hi all!
I'm trying to create a program that produces a memory leak. I have a program that looks like it works, but I was wanting to verify whether it actually is causing a memory leak, and that it's not just some other type of issue. It's in C++, which is a language I have very little experience in. I've mostly used C#, but as it is garbage collected I thought that it may be easier to use a different language.
My code is as follows:
void memLeak()
{
int *data = new int;
*data = 15;
int *data1 = new int;
*data = 15;
///
/// ... all the way up to twenty of these...
///
int *data20 = new int;
*data = 15;
}
int main(){
int ch = 1;
int x = 0;
while (ch == 1)
{
while (x < x+1000000)
{
memLeak();
x++;
}
x = 0;
}
return 0;
}
It compiles without any issues, and runs in a blank console. By monitoring it in Task Manager, I can see that it gets up to about 2GB memory usage, but at that point it halts and this message appears:
This application has requested the runtime to terminate it in an unusual way
The process in Task Manager then ends and disappears. My question: is this program causing a memory leak, and then Windows is just terminating it to prevent it from getting to a critical state? Or is my program actually doing something different?
Cheers for any help!