xlinuks
June 11th, 2008, 06:46 PM
Hi,
I have an std:vector that contains pointers to objects.
So, say the pointer to my vector is called pMyVector, what does
this do:
vector<SomeObject*> *pMyVector = new vector<SomeObject*>();
pMyVector->add( new SomeObject() );
pMyVector->add( new SomeObject() );
//and so on
//what does the following line do?
delete pMyVector;
Is it correct that it?:
1) Calls vector's clear() method to delete the objects, and since there are only pointers to objects it only deletes the pointers but the objects themselves stay in memory.
2) Destroys the vector.
If not please let me know how to correctly delete the vector and the data it contains to avoid memory leaks.
I have an std:vector that contains pointers to objects.
So, say the pointer to my vector is called pMyVector, what does
this do:
vector<SomeObject*> *pMyVector = new vector<SomeObject*>();
pMyVector->add( new SomeObject() );
pMyVector->add( new SomeObject() );
//and so on
//what does the following line do?
delete pMyVector;
Is it correct that it?:
1) Calls vector's clear() method to delete the objects, and since there are only pointers to objects it only deletes the pointers but the objects themselves stay in memory.
2) Destroys the vector.
If not please let me know how to correctly delete the vector and the data it contains to avoid memory leaks.