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:
Everything you allocate with new
you have to delete
later on. Objects that you don't explicitly allocate with new
shouldn't you delete
.
If you don't want to manage the objects manually but want the vector to "own" them, it might be better to store the objects by value instead of storing pointers to them. So instead of std::vector
you could use std::vector
.