Annoying Direct3D memory leak problem

Started by
1 comment, last by Scoob Droolins 19 years, 6 months ago
I am having an extremely annoying problem with Direct3D memory leaks. I am going through the list of memory leaks, starting at the bottom, and putting the AllocID into the Break on Alloc ID field in the D3D control panel. None originate on a Create* line, the ones I can recall are on IDirect3DSwapChain8::Present, and IDirect3DDevice8::Clear. They are all less than 200 bytes. There are more leaks dumped above, but I believe they will go away when I get rid of these. I am using CComPtr for everything, I do not have a single dumb Direct3D pointer anywhere. I tested to see if ATLASSERT is being compiled in, and it is. I made a class and derived all of my Direct3D interface wrappers from it, where the constructor ads itself to a list, the destructor removes them. Right before the CComPtr::Release that represents my device, I dump all the leaks in that list, and there are none. I am baffled!
Advertisement
I had a similar problem when I wrote my own smart pointer. My problem came about, if you have a function that returns a pointer, the CComPtr adds a reference that it isn't needed.

CComPtr<IDirect3D8> pD3D = Direct3DCreate8(D3D_SDK_VERSION);


After that line of code, pD3D has a ref count of 2, but should only have a count of one. I had to add an attach method that obtained ownership without adding a ref.

pD3D.attach(Direct3DCreate8(D3D_SDK_VERSION));


Maybe that will be helpful.
I have found Break on Alloc ID to be questionable - from run to run, the ID isn't always the same for a specific allocation ( at least in VC6 - it's better in .NET). First, run all the way to the end of your app, and note the ref count when you finally release the D3D device. This will give a good idea of how many 'leaks' there are. Next, try running your app with just create device, set video mode, reset video mode, destroy device, and see if it still leaks. Gradually add more resource creation (if you can) until it leaks. I have also found that some individual resource allocations (vbuf, texture, etc) seem to generate several alloc IDs.

joe
image space

This topic is closed to new replies.

Advertisement