Jump to content
  • Advertisement
Sign in to follow this  
SpiralGuru3d

d3d leaks

This topic is 4925 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

Hi all, I have a d3d application here that is leaking a small amount of memory when it exits. Direct3D9: (INFO) :MemFini! Direct3D9: (ERROR) :Memory still allocated! Alloc count = 126 Direct3D9: (ERROR) :Current Process (pid) = 000004a4 Direct3D9: (ERROR) :Memory Address: 0091690c lAllocID=1 dwSize=000047f8, ReturnAddr=01eb14db (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 0218987c lAllocID=9 dwSize=00009414, ReturnAddr=01ea8044 (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 0091bad4 lAllocID=10 dwSize=00000008, ReturnAddr=01ea8132 (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 02192cc4 lAllocID=11 dwSize=00000e40, ReturnAddr=01ea970f (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 0091b144 lAllocID=22 dwSize=000006bc, ReturnAddr=01ec2f4b (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 02193b3c lAllocID=24 dwSize=00009b40, ReturnAddr=01eb4a19 (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 0091b83c lAllocID=26 dwSize=00000008, ReturnAddr=01eb4b5d (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 02180064 lAllocID=28 dwSize=00003508, ReturnAddr=01eb14db (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 0091b884 lAllocID=29 dwSize=00000198, ReturnAddr=01eb14db (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 0091ba5c lAllocID=30 dwSize=00000030, ReturnAddr=01eb14db (pid=000004a4) Direct3D9: (ERROR) :Memory Address: 021835ac lAllocID=31 dwSize=00001020, ReturnAddr=01eb14db (pid=000004a4) Direct3D9: (ERROR) :Total Memory Unfreed From Current Process = 119624 bytes 1) Given those allocIDs, or even addresses, is there any way I can find where the allocs were made? 2) Is ReturnAddr the d3d call that allocated the memory? If so, I know 5 of the leaks are of the same type.. 3) The AllocCount is given as 126, but I only get 11 leaks detailed. What does the 126 refer to? Many thanks in advance. -scott p.s boundschecker doesn't help, the app quits without report.

Share this post


Link to post
Share on other sites
Advertisement
1) Open the DirectX control panel (Control Panel->DirectX) and enter an AllocId in the "Break On AllocID" field. It does what it says.

2) Probably

3) I don't know what AllocCount stands for - I just ignore it

Share this post


Link to post
Share on other sites
And start with the last id. Id of 1 is the device and that is not being released because of a previous leak so no point beaking on that.

Share this post


Link to post
Share on other sites
All the leaks lead to:

iD3D9 = Direct3DCreate9( D3D_SDK_VERSION );

or

iD3D9->CreateDevice(..,..,..,..,..,&iD3DDev9 );

---

I release them:

iD3D9->Release()

and

iD3DDev9->Release()

---

The device in particular returns a high number of existing references.

If I do

while( 0L != iD3DDev9->Release() );

I get crashes later when releaseing other resources.

??

Share this post


Link to post
Share on other sites
Quote:
Original post by SpiralGuru3d
I release them:

iD3D9->Release()

and

iD3DDev9->Release()

IIRC, you have to release the IDirect3DDevice9 *before* the IDirect3D9 object. In general, you need to release objects in the reverse order that you created them in (ie object created last would be released first).

Share this post


Link to post
Share on other sites
thanks. I just checked, I do release them in the right order.

Do I need to release them with the while loop, until the ref count is zero?

I only create the device once in the execution path I'm testing, why does it return so many references when I release it?

Share this post


Link to post
Share on other sites
The problem isn't that the device needs to be released more times, the problem is that something in your program isn't calling Release() on a resource when it should. If you look through the docs you'll see that some functions (such as GetRenderTarget()) add a reference to the resource in question. You MUST call release on that resource whenever this happens. So you need to go through your code, find all D3D functions that add a reference to a resource (there all listed in the docs) and make sure you are releasing that resource after the call.
In addition when you are done with a resource, you call release on it to destroy it. When you call Release() it returns the current reference count after the release, so whenever you destroy a resource check the reference count and assert on it if its non-zero. This way you'll know which resources haven't been properly released previously. I use something like this in debug:
SAFE_DESTROY(p)
{
if (p)
{ u32 uRefCnt = p->Release();
assert(uRefCnt==0); p = NULL;
}
}

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!