I have a vector that I fill with pointers to objects. I am trying to learn good memory management, and have a few general questions:
- Is it true that when I am done with the vector, I must loop through it and call delete on each pointer?
- Why don't I have to call delete on the vector or any other variable I declare without the new statement, but delete must be called on pointers?
- Does C++ handle freeing the pointers' memory for me if the vector is declared in a function which returns (causing the vector to go out of scope)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…