// C++ doesn’t do garbage collection--you have to do it yourself. // // The best way is to use a container, like vector<> or string<>, // which handles the memory management for you. // // If you do have to do it yourself, unique_ptr can help. #include using namespace std; int main() { for (long i=1; ; i++) { char *p = new char[1'000'000'000]; // 1GB p[0] = 'X'; p[1] = '\0'; cout << "Pass #" << i << ": p=" << p << '\n'; // Oops--forgot to free that memory! } return 0; }