#include <iostream>
using namespace std;
class String{
public:
char *Str;
String(){
Str = new char[10000000];
}
~String(){
delete Str;
}
};
int main(){
String my1;
for(int i=0; i< 100000; i++){
String my2;
my2 = my1;
}
return 0;
}
-------------------------
Because inside the constructor, a new memory is allocated each time a
new object is created. And inside the for loop, my2.Str is repointed to
my1.Str, and thus the memory orginally allocated for my2 will be
"lost".
And if we run on Linux, the host should be expected to memory drained
to dry. But it didn't on my box. Wonder why...