D3DX memory leaks

Started by
6 comments, last by MJP 15 years, 5 months ago
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!
Advertisement
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.
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.
I use delete[] for the buffers and release for the pointers
You should be calling Release() on any ID3DXBuffer objects.
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.
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.
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.

This topic is closed to new replies.

Advertisement