Memory Leaks Are Bad, Mmmkay

Published November 28, 2007
Advertisement
So I've been very bad, and have been leaking memory in ISO. Yeah, yeah, tar and feather me for it later.

I set out to fix them tonight, but I'm pretty sure I'm going out of my fucking mind. All of my reported leaks are D3D handles, which is especially bad, but I can't for the life of me figure out why they're still getting reported.

For example, most of my leaks appear to be from my textures. I have my out wrapper around the D3D texture interface, which is as follows (this code has changed a bit in the past hour or two, so bear with all the commented out nonsense):
Texture.h
#ifndef TEXTURE_H#define TEXTURE_H#define D3D_DEBUG_INFO#include #include #include #include #include "../../Main/Header Files/Resource.h"namespace ISO{	namespace Graphics	{		class Texture		{		public:			Texture(LPDIRECT3DDEVICE9 device = NULL, std::string filename = "");			/*Texture(const Texture& tex);			const Texture& operator=(const Texture& tex);*/			~Texture();			LPDIRECT3DTEXTURE9	GetTexturePointer() const;			const std::string& GetFileName() const;			ULONG Release();		private:			std::string			m_Filename;//			Base::auto_resource	m_Texture;			mutable LPDIRECT3DTEXTURE9 m_Texture;		};	}}#endif


Texture.cpp
#include #include "../Header Files/Texture.h"ISO::Graphics::Texture::Texture(LPDIRECT3DDEVICE9 device, std::string filename): m_Filename(filename),m_Texture(NULL){	if (!device)	{		return;	}	LPDIRECT3DTEXTURE9	texture;	HRESULT hr = D3DXCreateTextureFromFile(device, filename.c_str(), &texture);	if (FAILED(hr))	{		return;	}	m_Texture = texture;}//ISO::Graphics::Texture::Texture(ISO::Graphics::Texture &tex)//{//	//*m_Texture = *tex.GetTexturePointer();//}//ISO::Graphics::Texture::Texture(const Texture& tex)//: m_Texture(tex.m_Texture)//{//	tex.m_Texture = NULL;//}////const ISO::Graphics::Texture& ISO::Graphics::Texture::operator=(const ISO::Graphics::Texture& tex)//{//	m_Texture = tex.m_Texture;//	tex.m_Texture = NULL;//	return *this;//}ISO::Graphics::Texture::~Texture(){	/*if (m_Texture)	{		m_Texture->Release();	}*/}LPDIRECT3DTEXTURE9 ISO::Graphics::Texture::GetTexturePointer() const{	return m_Texture;//.Get();}const std::string& ISO::Graphics::Texture::GetFileName() const{	return m_Filename;}ULONG ISO::Graphics::Texture::Release(){	assert(m_Texture);	return m_Texture->Release();}


Simple enough, unless (as is highly possible) I'm missing something obvious. I keep a std::vector of these Textures in my renderer, which theoretically get released when the renderer is destroyed:
Renderer.cpp
ISO::Graphics::Renderer::~Renderer(){	for (unsigned i = 0; i < m_Tiles.size(); ++i)	{		delete m_Tiles.Geometry;	}	for (unsigned i = 0; i < m_UIBuffers.size(); ++i)	{		delete m_UIBuffers.first;	}	for (unsigned i = 0; i < m_TextureBuffer.size(); ++i)	{		//delete m_TextureBuffer;		m_TextureBuffer.Release();	}	//m_TextureBuffer.clear();	if (m_D3DDevice)	{		m_D3DDevice->Release();		//m_D3DDevice = NULL;	}	if (m_D3D)	{		m_D3D->Release();		//m_D3D = NULL;	}	delete m_Selector;	delete m_MasterGeometry;}


I've set breakpoints in the Renderer destructor, and it is indeed getting called. Texture->Release is returning 0, so it doesn't appear that I have any dangling references out there. Why, then, do I still get a ton of leaks reported coming from my textures?

I am confused and tired. Little help [grin]?
0 likes 2 comments

Comments

Evil Steve
If you have a texture bound on the device (Through SetTexture()), it won't be freed until the device is released. And if you have a reference to any D3D object, the device won't get released.

Although if you're seeing Release() return 0 for all texture anyway, it should be fine.

Have you tried commenting out chunks of code till the leak goes away? That should at least help narrow it down (Although I appreciate that "commenting out chunks of code" can be a bit difficult in complex engines).
November 28, 2007 05:41 AM
Driv3MeFar
I've cleaned up all my D3D leaks. And by "all", I mean one. There was one texture that I was using for debugging purposes that I had forgotten about. Strange that because of one unreleased texture I was getting a reported 155 memory leaks. I suppose the dangling reference stopped the device from actually being released, but all my Release functions were returning 0, so there shouldn't have been any cleanup problem. Or maybe I don't know what I'm talking about *shrug*

Thanks for the advice, Evil Steve .
November 28, 2007 09:56 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

/facepalm

1720 views

Baby Steps

1280 views

...

720 views

Stuff

1320 views

Productivity++

1207 views

Rock Band FTW

1239 views

Seattle Opera

1283 views

Christ

1208 views

I maek gaem!

1184 views
Advertisement