Hi, I can't figure out why the following is leaking memory - when I run the application the memory usage just keeps going up. Anyone see something wrong with this code: I'm adding some initial values to the 2d deque like so: Code: deque dq; for(int i = 0; i < 10; i++) { dq.push_back(deque()); for(int j = 0; j < 10; j++) { dq[i].push_back(new MyType(1,2)); } } And then during the running of the application, the user periodically performs actions that invoke this: Code: for(int j = 0; j < 10; j++) { delete dq.back()[j]; } dq.pop_back(); dq.push_front(deque()); for(int j = 9; j >= 0; j--) { dq.front().push_front(new MyType(1,2)); } or this: Code: for(int i = 0; i < 10; i++) { dq[i].push_front(new MyType(1,2)); delete dq[i].back(); dq[i].pop_back(); } Much thanks for any help!
I see that you are doing manual memory management. The idea behind what I am saying is simply: do not do manual memory management. Storing the objects by value accomplishes that, as does using a smart pointer like std::tr1::shared_ptr. If you have access to Boost, another possibility is to use a boost::ptr_deque.