Archived

This topic is now archived and is closed to further replies.

aker_jus

Releasing d3d interface

Recommended Posts

Hello, I am wondering, if I use: LPDIRECT3D9 d3d9 = something->GetDirect3D(); Do I have to release this d3d9 instance too, or do I just release the instance I first created with Direct3DCreate9? This applies to other interfaces too. Thanx

Share this post


Link to post
Share on other sites
i don''t know anything about the managed dx9 if thats what you are using, but as long as its not creating a totally new interface, ie its returning the pointer to an already existing interface, then no. you only have to release it once.

Share this post


Link to post
Share on other sites
I have not tested how DirectX handles this, but DirectX is made by Mircosoft and Microsoft has a page which states that you must call Release on it.

See "Reference-Counting Rules" Rule 1d in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncomg/html/msdn_therules.asp

Share this post


Link to post
Share on other sites
then just use a saferelease macro and dont worry about it. as long as you initialize all of the interfaces to null before trying to create/get them:


#define SafeRelease(x) { if(x) { (x)->Release(); (x) = NULL; }}

just make sure you initialize the LPDIRECT3D9 to null, so in your example:

LPDIRECT3D9 d3d9 = NULL;
d3d9 = something->GetDirect3D();

then later on, when you want to release it:

SafeRelease(d3d9);


Share this post


Link to post
Share on other sites