No Memory leaks with exit(1) function call??? 😳
I was testing a memory leak tool for Mac out today that I found here: [https://dr-rost.medium.com/detect-memory-leaks-on-macos-4cf257529aa] and I noticed that the following code 'test.cpp' #include <iostream> using namespace std; int main() { string *x = new string; *x = "hello"; cout << (*x)[0]; } I compile: gcc -lstdc++ test.cpp -o test.out Then I run the memory leak detector: leaks -atExit -- ./test.out | grep LEAK I of course get a memory leak: 1 (32 bytes) ROOT LEAK: 0x60000143d120 [32] But if I properly deallocate memory by adding `delete x;' then compile and run leak detector as before I get no memory leak, as expected. However, when I change 'delete x;' to 'exit(1);' (or if I add exit(1) after delete x;) I get no memory leak??? But how can this be? I haven't deallocated the memory, so why don't I get a memory leak?