• Advertisement
Sign in to follow this  

Memory leak

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

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
Advertisement
A single memory leak typically causes a chain of leaks. Objects referencing the leaked object aren't destroyed, so they also are leaked. The problem should be coming from the object with the highest alloc id.

Share this post


Link to post
Share on other sites
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?

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
do you have any surfaces that you did not remove for example your backbuffer if you had allocated one when you call GetBackBuffer.
Sorry just ignore that i see that you have deallocated it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement