Jump to content
  • Advertisement
Sign in to follow this  

would this cause a memory leak?

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

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
use the _CRTDBG_MAP_ALLOC macro when you suspect having a memory leak.This will tell you -in the output window in Visual studio- if there's unallocated memory in the application.

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!