Sign in to follow this  
Calin

Memory leak

Recommended Posts

While seaching the forum for a solution for my unfreed memory problem I found a thread that contains the following advice:
Quote:
jollyjeffers: Also, on the same page, are some other options - such as the "maximum validation" I mentioned. Of interest there should be a "Break on AllocID" option with an associated text box. In this text box you enter the values that the debug runtime spits out. 1, 8, 9 for yours. Click "Apply" to commit your changes. Fire up your IDE (VStudio for example) and launch your application as a DEBUG build. As soon as you hit the allocID the IDE will hit a breakpoint. Whatever line it's pointing at (probably a "Create...()" call) is the object that the later memory leak is complaining about. For example, if AllocID-9 breakpoints on a CreateVertexBuffer() call, then the memory leak resides in the fact that you (in your abnormal termination) haven't SAFE_RELEASE()'d it's reference. You need to put the relevant release code in your termination/error handling code.
Using this instructions I discovered that many objects that do have a release code, appear in the debugging output as unreleased ( i.e: allocID 1, 9,11,12 etc). Here is a code snippet from my ShutDown function:
LPDIRECT3D9 g_pD3D;
IDirect3DDevice9* g_pDevice; 
LPDIRECT3DSURFACE9 g_pBackSurface;
HWND g_hWnd;

// [code removed]

HRESULT GameShutDown()
{
    //[code removed]
   
        //--------------------------------
	// Shut Down Direct3D Device  
	//--------------------------------

	if(g_pBackSurface)
		g_pBackSurface->Release();
	if(g_pDevice)
		g_pDevice->Release();

	if(g_pD3D != NULL)
	{
		g_pD3D->Release();
		g_pD3D = NULL;
	}

	// Mouse destructor handles the  DirectInput deallocation
	 delete g_pDIMouse;
	 
	return S_OK;
}   



Could someone give a suggestion on how to solve this problem? [Edited by - Calin on November 6, 2005 4:15:45 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Calin
A D3DLIGHT9 object has the highest allocID. But how can I release a light object if there is no such a call for D3DLIGHT9 objects. Do I use delete for this?


You don't need to release a D3DLIGHT9, it's merely a simple struct. If you wanted to play it safe, you would go: Device->SetLight(id, NULL); and make sure the light is disabled.

Share this post


Link to post
Share on other sites

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