Very large execution random behaviour
I have an executable which calls a function from DLL project. DLL project function has one for loop which gets executed for 3300 times. At the start of loop, I have called below function for testing purpose: double getUsedMemoryMB() { PROCESS_MEMORY_COUNTERS pmc; GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)); return static_cast<double>(pmc.WorkingSetSize) / static_cast<double>(1024 * 1024); } This function returns 170 for first 38 iterations in a loop. For 39th iteration, i got result as 171. For iteration 40 to 73, value is 172 and later at iteration 583, I could observe value as 186. Question is what this function returns? Is it stack memory used by executable process? Why it is getting increased randomly? I started logging this information as I have tried executing for loop two times and both times it got crashed at different iterations and hence I thought about memory issue. How to solve this issue? Unfortunately, I cannot share code due to privacy constraints, but code inside for loop calls a function which do some processing and generate a file on disk. First one minute of code execution generates around 40 files which gets decreased to 40 in a hour post code execution time reaches around 30 Hours. Any thought to solve this issue will be a big help.