I just have a little question regarding how the stl containers handles memory.
I have allocated memory for a object and then the object is added to an stl list:
Code:
std::list<NewUser> userlist;
......
// adds item to vector
NewUser *user = new NewUser();
userlist.push_back(*user);
.......
// removes item from vector
userlist.pop_front();
I just wondered if the pop_front function frees the memory that I allocated earlier.
If not, how would i do that. The pop_front() function does'nt return the item popped off, does it? If it does I could just run delete on it, but I don't think you can do that?
BTW, the "user" pointer will only point to the current object created, so I will not have a pointer to the objects since this will be run in a function.
The best solution here maybe would not to use a pointer to the object at all, because I don't think I will need them.
But anyway, I would really like to know how it works.