Sign in to follow this  
Locutusborg

D3DX memory leaks

Recommended Posts

After building my program, I get the message that I am having D3DX memory leaks. (I specially say D3DX, because they are not 'normal' memory leaks you can find using _CrtDumpMemoryLeaks(); ) Apparantly, they are created when calling D3DXLoadMeshFromX. when I add another mesh to the program, changing nothing else, two extra leaks are found. At the end of the program I delete the texture and materialbuffer, aswell as the pointer for every mesh. (these are the only buffers I create, as far as I know) I have read about a lot of people having this problem, but I cant find the solution. Does anyone have an idea? THANKS!

Share this post


Link to post
Share on other sites
Have you told D3D to use the debug run time, it will dump out the leaks for you so you can see them. I also recommend wrapping each pointer with a Com class, such as ATLs CComPtr, this will make sure you are AddRef()'ing and Release()'ing correctly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Locutusborg
At the end of the program I delete the texture and materialbuffer, aswell as the pointer for every mesh. (these are the only buffers I create, as far as I know)

Are you deleting them with delete or are you releasing them by calling Release()? There's a very important difference between the two.

Share this post


Link to post
Share on other sites
Thanks for the hint. It turns out, I was deleting only the pointers to the buffer, but forgot to release the materialbuffer, which I only use as a local variable in the loadmesh function.
Strange though that each materialbuffer accounts for 2 allocations.

Share this post


Link to post
Share on other sites
Quote:
Original post by Locutusborg
Strange though that each materialbuffer accounts for 2 allocations.
It's probably one for the ID3DXBuffer object, and one for the actual contents of the buffer.

Share this post


Link to post
Share on other sites
Don't delete the pointers to the buffers. Releasing the interface pointer will take care of it...the object allocated the memory and is responsible for cleaning it up.

Also on a related note, using COM smart pointers can work wonders for preventing memory leaks. I prefer CComPtr myself, but that's only available if you have access to ATL. _com_ptr_t on the other hand is available with any version of C++, but isn't quite as nice to use. It's also possible to use boost::shared_ptr to handle COM pointers. There's also this class on CodeProject, but I have no idea how well that works.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this