Sign in to follow this  

would this cause a memory leak?

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

the following code works, but does it cause a memory leak? It creates a pointer and returns it, so Im thinking it does.
IDirect3DTexture8 *cSprite::MakeTexture(const char *imgsrc)
{
DWORD dwKeyColor = D3DCOLOR_XRGB(0, 0, 0);
IDirect3DTexture8 *pTemp;
ghr = D3DXCreateTextureFromFileEx(pGraphics->pD3DDevice, //device
mgsrc,//src
256,//width
256, //height
D3DX_DEFAULT, //mip levels
NULL, //usage
D3DFMT_A8R8G8B8, //format
D3DPOOL_DEFAULT, //mem pool
D3DX_DEFAULT, //pool
D3DX_DEFAULT, //mip filter
dwKeyColor, //coorkey (black = transparent)
NULL, //psrc info
NULL, //pallette
&pTemp);

return pTemp;
}

[Edited by - Coder on September 11, 2004 10:42:17 PM]

Share this post


Link to post
Share on other sites
A memory leak occurs when you allocate memory (like with "new" or a creation function) but never deallocate it (like with "delete" or obj->Release()). If you eventually deallocate the memory (not necessarily in this function), there's no leak. If you don't, there is. Just make sure that you call Release() on this object before you lose all references to it, and you'll be fine.

Share this post


Link to post
Share on other sites
Right. When you're talking about pointers, it's important to remember that a memory leak is not caused by losing track of the pointer, but by losing track of the pointed-to-object. If I had 3 pointers to the same block of memory, I'd only free 1 of them.

Share this post


Link to post
Share on other sites

This topic is 4840 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this