I cannot create a memory leak
I am currently testing out memory leaks in C++ and found out that I cannot get the ram to go close to 99%. I mainly just wanted to test it and I remember once I had managed to throttle the computer before closing the program. However, I am currently doing
while (true)
{
int* x = new int[100];
}
It takes a while to accumulate memory but I also noticed the program closes on its own. In VS it will give me badalloc exception. So I went and tested with release. And there also, the program accumulates around 2 gigs (I have 32 gigabytes and 40% was currently used by other processes) before closing on its own. I remember I once managed to get it to close to 90% usage but I cannot seem to get there anymore before it closes on its own. I checked via task manager and the debug window in visual studio.
I am wondering, is this the operating system that figures out that the program is allocating cluelessly and shuts it off or what exactly is making it close on its own? Shouldnt the program just run? My PC doesnt freeze up or anything, like mentioned it slowly approaches 2 gigabytes before it shuts off on its own. I was running the release config.
Please do let me know the process behind all this. Yes I know its kind of stupid but I am learning and was just curious how fast it would hit 99% RAM usage but it doesnt do it.
TIA.
The symptoms you describe seem logical for a 32bit program on Windows: a maximum memory usage of 2GB. You could change some property on the exe (or during compilation) to use a bit more of memory. If you like to know more, you can read: https://superuser.com/questions/1163749/why-do-32-bit-processes-have-a-2-gb-ram-limit
The best to do is to change your compiler flags to create a 64 bit executable, see https://docs.microsoft.com/en-us/cpp/build/how-to-configure-visual-cpp-projects-to-target-64-bit-platforms