Am I freeing up the memory used in my program?

This is a discussion on Am I freeing up the memory used in my program? within the C++ Programming forums, part of the General Programming Boards category; Hi All,
I've written a program for an assignment which utilises doubly-linked lists using the STL.
I create a class ...

So in the following code, I'm reading a line into a list of chars which is saved to a row object, then I add that row object to a list of row objects (maze_rows) and subsequently clear the list of chars and begin again.

What I want to know is, is this effectively freeing up any memory I had been using for these lists? My grasp on memory management is a bit hazy because I've only ever programmed in Java before and it wasn't that necessary.

The clear() member function of std::list destroys the elements and sets the size of the container to 0. Although it may happen, especially since this is a doubly linked list, I do not think that you should be so sure that the memory will be released.

Not to worry: when the container object goes out of scope, any remaining elements will be destroyed, and its associated memory will be released. Therefore, you do not need to do any special action to try and ensure that memory will be released.

You could make a local scope to make sure the containers go out of scope before the function ends, too. But so long as you are using STL containers (unless you are working with pointers), all memory will be cleaned up correctly when they go out of scope. No need to worry.