Example of Garbage Collection :-


#include<iostream>
 
class A {
int x;
public:
A() { x = 0; ++x; }
};
 
int main() {
for (int i = 0; i < 1000000000; ++i) {
A *a = new A();
delete a;
}
std::cout << "DING!" << std::endl;
}

Output:


Length=10

			



Note:-

If garbage collection program does not run on your pc, then plz visit below the link...

1. Garbage Collection Detail with Program
2. Garbage collection Details (Wikipedia)
Previous Next