I have a C++98 test code. This code make a horrible memory lake. Why? Memory consumption after the release of pointers is the same as before the release.
#include <iostream>
#include "string.h"
using namespace std;
void test();
int main() {
test();
cout << "Freed" << endl;
int input;
cin >> input;
cout << "Good bye" << endl;
return 0;
}
void test() {
int input;
int count = 40000000;
const char *str = "9 770123456789123456123";
char **pMsg = new char *[count];
cout << "Register: " << count << endl;
cin >> input;
for (int i = 0; i < count; i++) {
pMsg[i] = new char[strlen(str) + 1];
strcpy(pMsg[i], str);
}
cout << "Full pointers" << endl;
cin >> input;
for (int i = 0; i < count; i++) {
delete[] pMsg[i];
}
delete[] pMsg;
}