   std::vector Not Releasing ID3DXMesh*
  I'm trying to create an easy to manager container for my ID3DXMesh* objects. I decided the best way was to use a pseudo-RAII approach and encapsulate the mesh in another class like so:class Mesh{public:Mesh(void) { mesh = NULL; }~Mesh(void) { if(mesh) { mesh->Release(); } }ID3DXMesh* mesh;};Then I simply created my vector of objects like normalvector<Mesh> meshes;And then when my program quits I'm just using the clear() function to empty the vector which should call all the destructors and delete the meshes, but I'm getting a ton of unfreed memory from this. Why isn't this working like I want it to? I am making sure to clear out the vector before releasing the IDirect3D9* or IDirect3DDevice9* objects just in case that matters. Any ideas?   
  The best thing to use here is the ComPtr that can be found in atlbase ( i think ).My implementation is here:#ifndefCOM_PTR_H#defineCOM_PTR_H#include <assert.h>template < typename T >class ComPtr{typedefT*_pT;public://copy constructor from an object pointerComPtr( T* other = 0) :_p( 0 ){_p = other;AddRef();}//copy constructor from another com_ptrComPtr( const ComPtr< T >& other ) :_p( 0 ){_p = other.Get();AddRef();}~ComPtr() {Release();}// assignment from T*ComPtr< T >& operator=( T* rhs ) {Release();_p = rhs;return *this;}// assignment from another com_ptrComPtr< T >& operator=( ComPtr< T >& rhs ) {// Release thisRelease();_p = rhs.Get();AddRef();return *this;}// DereferencingT* operator->() {return _p;}T& operator*(){return *_p;}// Increment the reference countvoidAddRef() {if ( _p ){_p->AddRef();}}// Decrement the reference countvoidRelease() {if ( _p ){_p->Release();}}// ResetvoidReset() {Release();_p = NULL;}T* Get() const{return _p;}T** Address(){return &_p;}unsigned longRef(){if ( _p ){_p->AddRef();return _p->Release();}return 0;}private:T*_p;};#endifStore a ComPtr object, that wraps the COM object pointer, manages reference counting etc, into the std::vector.Hope that helps mate,Dave   ;  The most likely cause for the leaks is not providing the copy constructor and/or assignment operator for your Mesh class properly.   ;  Clearing a vector container is NOT going to cause your class destructor to get called.  It just empties it.  So just let your app exit without doing the clear.  I use clear when I don't want my app to delete something because I am copying the vector to another.;Quote:Original post by DXnutClearing a vector container is NOT going to cause your class destructor to get called.He has a container of objects, not a container of pointers. The destructor will get called.;  I suspect that somewhere else where you're using the meshes isn't cleaning up right.  Breakpoint the destructor, and examine the value returned by the Release() call.  If something else has increased the refcount, and assuming D3DX does the right thing, it'll return > 0.  If it returns 0, then it should be cleaned up.   