The following is the best "minimum working example" I can construct for now. I would like to understand if the following code leaks memory.
// Class CTest
class CTest {
vector<int> Elements;
CTest (vector<int>&);
~CTest ();
};
CTest::CTest (vector<int>& Elements_) {
this->Elements = Elements_;
}
CTest::~CTest () {
}
// main
int main (int argc, char *argv[]) {
vector<CTest> V;
for (auto i = 0; i < 10; i++) {
vector<int> U;
for (auto j = i; j < i + 5; j++) U.push_back (j);
V.push_back (*(new CTest (U)));
}
// Do whatever
return 0;
}
Am I correct in thinking that since there isn't a corresponding invocation of delete
for each invocation of new
, this programme does indeed leak memory?