Skip to main content
GameDev.net gamedev.net
🔒 Locked

Memory Leak? [FIXED]

Started by NovaCaine Oct 11, 2005 at 8:16 PM 6 replies 750+ views
Original Post
NovaCaine
NovaCaine
Hey all, Having a fun time tracking down memory leaks, using Memory Manager from Fluid Studios . This returns with me no longer having memory leaks, but i notice that when running my app (in debug) the memory grows about 4 - 12K every second (according to Task manager). Is this normal? or do i have a small leak somewhere that gets cleaned up on exit. Should I even bother trying to trck it down? While stepping through my code's render and update functions, it doesn't increment every frame, seems more like every second worth of frames it will increment and not fall back down. Any insight would be great. [Edited by - NovaCaine on October 11, 2005 10:00:07 PM]
jollyjeffers
jollyjeffers
If you run your application with the debug runtimes, preferably with maximum output, do you get a series of errors on the exit of your application?

If you check he "break on memory leak" box you should be able to get a good idea of whether you're not releasing any resources [smile]

best regards,
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
NovaCaine
NovaCaine
My application exits fine as far as i can tell. FYI im also running with DX Debug info on max.

Output last time i ran my app: (just the exiting part)
Quote:

The thread 'Win32 Thread' (0xd30) has exited with code 0 (0x0).
The thread 'InitializeFusion' (0x2d8) has exited with code 0 (0x0).
Direct3D9: :====> ENTER: DLLMAIN(03d5d6e0): Process Detach 00000920, tid=00000860
Direct3D9: (INFO) :MemFini!
Direct3D9: :====> EXIT: DLLMAIN(03d5d6e0): Process Detach 00000920
The program '[2336] D3D App.exe: Native' has exited with code 0 (0x0).
The program '[2336] D3D App.exe: Managed' has exited with code 0 (0x0).


UPDATE:

Now running with "Break on Memory Leak" box check. Still same thing.
jollyjeffers
jollyjeffers
Well I'd suggest you spend your time looking elsewhere for the memory leak. The DX debug runtimes are pretty good at their job [smile]

I have used Fluid Studio's "mmgr" checker and still got leaks - but I attributed them to system allocations. There is the problem that the "mmgr" checker appears a bit too early in the execution cycle for STL/system resources and is exited before they're cleaned up.

Do more tests, but if it's a fairly marginal thing then it is worth considering that the tools just aren't accurate enough [wink]

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
Prototype
Prototype
If you are using STLport, you have to #define STLP_DEBUG_ALLOC for mmgr to work correctly. At least, that's what I found. Similar problems may appear with other libraries that also override new/delete etc.

OT: I had the same problem. It turned out to be a vector that should have got cleared every frame but it kept growing in release mode. As it got properly destructed, the growth was not reported as a memory leak. These things are hard to track, maybe you have a similar issue.
NovaCaine
NovaCaine
Quote:
Original post by Prototype
If you are using STLport, you have to #define STLP_DEBUG_ALLOC for mmgr to work correctly. At least, that's what I found. Similar problems may appear with other libraries that also override new/delete etc.


whats STLport? Im currently building with VC++ 2005 Beta 2 and the DirectX August 2005 SDK.

Quote:

OT: I had the same problem. It turned out to be a vector that should have got cleared every frame but it kept growing in release mode. As it got properly destructed, the growth was not reported as a memory leak. These things are hard to track, maybe you have a similar issue.


Well ive managed to track the leak down into my scene graph. Basically my app at this stage is just a solar system ( bunch of models rotating around in such a way ) and if i comment out my render and update functions the leak goes away.

Any advice for tracking a leak in a tree??

NovaCaine
NovaCaine
It seems the leak is in the scene graph itself!

i figure i'll post some sode, see if anyone can spot something i shouldn't be doing.

CSceneGraph (m_pRoot is of type CNode)
bool CSceneGraph::Render() {	assert( m_pRoot );	if( !m_pRoot->PreRender() || !m_pRoot->Render() || !m_pRoot->RenderChildren() ) {		return false;	}	return true;}void CSceneGraph::Update( float p_fElapsedTime ) {	m_pRoot->Update(p_fElapsedTime);}


CNode
bool CNode::PreRender() {	if( FAILED( m_pStack->Push() ) || FAILED( m_pStack->MultMatrixLocal( &m_mWorldTrans ) ) || FAILED( m_pDevice->SetTransform( D3DTS_WORLD, m_pStack->GetTop() ) ) ) {		return false;	}	m_mCombinedWorld = (*m_pStack->GetTop());	return true;}bool CNode::PostRender(){    if( FAILED( m_pStack->Pop() ) ||        FAILED( m_pDevice->SetTransform( D3DTS_WORLD, m_pStack->GetTop() ) ) )    {        return false;    }    return true;}bool CNode::RenderChildren() {	std::list< CNode* >::iterator itr = m_lstChildren.begin();	while( itr != m_lstChildren.end() ) {		CNode* pTemp = (*itr);		assert( pTemp );		if( !pTemp->PreRender()	|| !pTemp->Render() || !pTemp->RenderChildren() || !pTemp->PostRender() ) {				return false;		}		++itr;	}	return true;}void CNode::Update( float p_fElapsedTime ) {	std::list< CNode* >::iterator itr = m_lstChildren.begin();	while( itr != m_lstChildren.end() ) {		CNode* pTemp = (*itr);		assert( pTemp );		pTemp->Update(p_fElapsedTime);		++itr;	}}


the render function just returns true, but somewhere in here is causing the leak. I am no longer calling Update on the SceneGraph but i am calling Render, which to my understanding should just be going through the tree. Could my iterator be the source of my leak?
NovaCaine
NovaCaine
YAY! found the leak, pretty obvious really.

Found i was pushing a new matrix onto the stack when i didnt need to (the root node's PreRender).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.