Given this code:
#include <iostream>
#include <sys/types.h>
#include <unistd.h>
int infiniteRecursion(int i) {
std::cout <<getpid() <<": "<< i << std::endl;
auto x = new int[i];
x[0] = 2;
int f[999999999];
return 1 + infiniteRecursion(i+1);
}
int main() {
auto b = new int[3000000000000];
auto c = new int[3000000000000];
auto d = new int[3000000000000];
auto e = new int[3000000000000];
auto f = new int[3000000000000];
auto g = new int[3000000000000];
std::cout<<getpid()<<std::endl;
std::cout<<infiniteRecursion(99999999999);
}
and running this command:
watch "smem -k | grep 31797"
where 31797 is the process id to see the memory grow. The problem is my system never slows down and the memory the PSS doesn't ever change. How would I be able to visualize a memory leak by watching memory grow?
Also secondary to this is I'm also trying to induce stack overflow but it's just not happening, this thing keeps going.
edit: when I comment out the cout statement in the recursive function the function instantly returns! and prints out 0. The program exits with code 0. Is there some optimization going on here?
Included screenshot because sort of relevant as this typically doesn't happen except for on my system: