Jump to content
  • Advertisement
Sign in to follow this  
DangerDave

(D3D) Debug data saying memory leak, but Release() returning 0

This topic is 4430 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a gazillion memory leaks in the D3D portion of my program. At the top of the list visual studio assails me with is lAllocID=1, which (should have realised from the beginning, but actually traced it) is the initial D3D object, m_pD3D. When my program exits, though, and I call m_pD3D->Release() in the destructor, the value it returns is 0, which means that there is no memory leak with this object, yes? What could cause this? How can I go about finding the culprit? Cheers,

Share this post


Link to post
Share on other sites
Advertisement
The returned value from Release() is not guaranteed to mean anything - thus relying on it is not a good idea as you've just found out [wink]

D3D objects form a heirarchy - leaking a child will also register a leak in the parent. Thus you almost always end up with both your IDirect3D9 and IDirect3DDevice9 in the leaked/lAllocID list.

As for finding the source of your leak... lots of fun that one! You might want to try using PIX to run a full call-stream capture and checking any "Alive" resources at the very end of execution.

Failing that, you might want to examine your code to make sure you're not missing any SAFE_RELEASE() statements - note that you might have to release an interface multiple times if you've caused it to be AddRef()'d.

I've not had the time to finish it (yet), but you can also use COM intefaces via IDirect3DResource9::SetPrivateData() to trace memory leaks. Thats a whole lot more involved though.

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
Failing that, you might want to examine your code to make sure you're not missing any SAFE_RELEASE() statements - note that you might have to release an interface multiple times if you've caused it to be AddRef()'d.


Ah cheers for the info, thats cleared up that mystery, but, err, SAFE_RELEASE(), what is that? Missing any.. I've not heard of it before..

Share this post


Link to post
Share on other sites
SAFE_RELEASE() is a macro that wraps the following statements:


#define SAFE_RELEASE(x) { if (x) delete x; x = NULL; }

Share this post


Link to post
Share on other sites
there are three: SAFE_RELEASE(), SAFE_DELETE() and SAFE_DELETE_ARRAY() - all simple macros defined in the DX SDK.

They don't do anything clever as such, just that they NULL the pointer after its deleted - which makes it easier to trap cases where you try and reuse a dead pointer [smile]

Check out an SDK header for the definitions; but off the top of my head:

#define SAFE_RELEASE(p) {if(p){(p)->Release();(p)=NULL;}}

hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by paradoxnj
SAFE_RELEASE() is a macro that wraps the following statements:

*** Source Snippet Removed ***

Eh, no. That would be SAFE_DELETE. SAFE_RELEASE is like:

#define SAFE_RELEASE(x) { if( x ) { x->Release(); x = 0; } }

Or, even better:
template< class T >
void SAFE_RELEASE( T *&x ) {
if( x ) {
x->Release();
x = 0;
}
}

jfl.

Share this post


Link to post
Share on other sites
OKOKOK get the general idea of a SAFE_ macros.. So they dont affect whether you get memory leaks or not.

If visual studio debug window displays Direct3D memory leaks, but doesnt display any memory leaks via crtdbg.h's _CrtMemDumpStatistics, does this mean that my memory leaks are all in video memory?

Does D3D memory leak detection ALWAYS refer to video memory leaks? Can I rule out any objects created with 'new' in this case, i.e. its definately an object created via a built-in D3D function?

Share this post


Link to post
Share on other sites
Quote:
Original post by DangerDave
...
If visual studio debug window displays Direct3D memory leaks, but doesnt display any memory leaks via crtdbg.h's _CrtMemDumpStatistics, does this mean that my memory leaks are all in video memory?
...



No, it just means that the D3D runtime is walking an internal list of orphaned D3D objects, spewing text to the debugger, then deleting these objects before the CRT memdump routine gets a chance to look for leaked memory blocks.

You should look to see that you didn't leave a D3D object selected into the device. Things like SetStreamSource, SetTexture, SetRenderTarget and similar ilk will prevent the device from being destroyed if an existing D3D object is still in use. Put things back to their default state (usually NULL) before you attempt to release the device and that could solve your problem.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!