-
Kosher or Leaky?
Does this code leak memory, or is the allocated vector object cleaned up?
Code:
void func(vector <int> veccie)
{
if(veccie.empty()) cout << "Empty" << endl;
else cout << "size: " << veccie.size() << "\t veccie[0]: " << veccie[0] << endl;
}
int main(int argc, char *argv[])
{
func(vector <int> (4, 23));
system("PAUSE");
return 0;
}
-
No memory leak. The destructor for std::vector cleans up after itself.
An example of the type of memory leak I think you were hinting at:
Code:
void foo(int* p) {
std::cout << *p << std::endl;
// delete p; is never called, and the only [see main] reference to this pointer is lost
// when this function returns.
}
int main( ) {
foo(new int);
}