I have "Vertex" class pointers in a list. I want to delete these pointers and free up the memory. I deleted the pointers in the first for loop and set these pointers to 0. but just to check whether the pointers have really been deleted and set to NULL, I accessed those pointers again in the second loop.
Why am I able to access them and access the attributes and members functions in the second loop when i have set their pointers to NULL in the first loop? Have I really freed up the memory? Is "vertexList.clear()" a save operation to do?
for(list<Vertex*>::iterator vertexListIterator = vertexList.begin() ; vertexListIterator != vertexList.end(); ++vertexListIterator)
{
Vertex* v = (Vertex*)(*vertexListIterator) ;
delete v ;
v = 0 ;
}
for(list<Vertex*>::iterator vertexListIterator = vertexList.begin() ; vertexListIterator != vertexList.end(); ++vertexListIterator)
{
Vertex* v = (Vertex*)(*vertexListIterator) ;
cout << "ID : "<< v->ID <<"\tAddress v : " << (long)(v) << endl ;
}
vertexList.clear() ;