D
deancoo
I'm pretty sure that the program bellow contains a memory leak. After
deleting the "hand_vector" instance, not all memory is released (only about
30%). It appears to me as though the instances of "hand" are still hanging
around. Are they not on the heap? Shouldn't they be released along with the
"hand_vector" instance? Thanks for any help.
d
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
class hand {
public:
vector<int> my_ints;
};
class hand_vector {
public:
vector<hand> myhands;
};
int main(int argc, char *argv[])
{
system("PAUSE");
hand_vector *myvector = new hand_vector;
hand v_stub;
for (int i=1; i<=5000000; i++) {
myvector->myhands.push_back(v_stub);
};
system("PAUSE");
vector<hand>::iterator j;
for (j=myvector->myhands.begin(); j!=myvector->myhands.end(); j++) {
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
};
system("PAUSE");
delete myvector;
system("PAUSE");
return EXIT_SUCCESS;
}
deleting the "hand_vector" instance, not all memory is released (only about
30%). It appears to me as though the instances of "hand" are still hanging
around. Are they not on the heap? Shouldn't they be released along with the
"hand_vector" instance? Thanks for any help.
d
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
class hand {
public:
vector<int> my_ints;
};
class hand_vector {
public:
vector<hand> myhands;
};
int main(int argc, char *argv[])
{
system("PAUSE");
hand_vector *myvector = new hand_vector;
hand v_stub;
for (int i=1; i<=5000000; i++) {
myvector->myhands.push_back(v_stub);
};
system("PAUSE");
vector<hand>::iterator j;
for (j=myvector->myhands.begin(); j!=myvector->myhands.end(); j++) {
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
j->my_ints.push_back(0);
};
system("PAUSE");
delete myvector;
system("PAUSE");
return EXIT_SUCCESS;
}