Reputation: 91
I've been trying to create a program that causes memory leak where it will crash my system.
The code below managed to cause a small spike of memory leak in my task manager.
#include <iostream>
using namespace std;
int main()
{
while(true)new int;
int * pp = nullptr;
pp = new int;
return 0;
}
If anyone could help me out on how to improve the memory leak, I would appreciate it!
Upvotes: 2
Views: 438
Reputation: 238301
To "improve" the memory leak.
new int
within the loop is sufficient, since it is potentially throwing, and thus the loop may not be proven to be infinite, but I'm not certain.The operating system should hopefully choose to kill your program when memory runs out.
Upvotes: 4