Huge memory leak when restarting Irrlicht...

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.

Re: Huge memory leak when restarting Irrlicht...

Postby robmar » Sat Mar 10, 2012 2:55 pm

Sounds good, whats the function call to get the total count?
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm

Re: Huge memory leak when restarting Irrlicht...

Postby CuteAlien » Sat Mar 10, 2012 4:45 pm

We're talking about maybe adding a feature, so obviously there can't be a function call yet.
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5358
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Huge memory leak when restarting Irrlicht...

Postby robmar » Sat Mar 10, 2012 5:33 pm

So I could just add a global counter and increment it in the grab function..
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm

Re: Huge memory leak when restarting Irrlicht...

Postby serengeor » Sat Mar 10, 2012 6:06 pm

robmar wrote:So I could just add a global counter and increment it in the grab function..

yeah, that's the idea
Working on game: Marrbles (Currently stopped).
User avatar
serengeor
 
Posts: 1695
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Huge memory leak when restarting Irrlicht...

Postby robmar » Mon Mar 12, 2012 4:48 pm

Okay, here are the details of my code in which I seem to have a memory leak somewhere.

From the head file for getMesh, it says not to drop the returned mesh pointer:-

virtual IAnimatedMesh* getMesh(const io::path& filename) = 0;
....
//! Get pointer to an animateable mesh. Loads the file if not loaded already. * \return Null if failed, otherwise pointer to the mesh.
* This pointer should not be dropped. See IReferenceCounted::drop() for more information.
**/
virtual IAnimatedMesh* getMesh(const io::path& filename) = 0;

So I don´t drop it, but before reloading a new scene from a file, I remove the meshes. Strangely, aftercalling getMeshCount and removing that number of meshes, when calling getMeshCoutn again, there are still meshes to delete!!! So I have to run the remove loop again! Is there an explication for this behaviour?

cpp Code: Select all
 
        // Ensure all 3D resources freed
        if ( m_pDriver )
        {
                // Delete all meshes
                if ( m_pSmgr )
                {
                        IAnimatedMesh *pMesh;
                        int i, iMl = 0;
                        IMeshCache* pMeshCache = m_pSmgr->getMeshCache();
                        if ( pMeshCache )
                        {
dml:            s32 iMeshCount = pMeshCache->getMeshCount();
                                for ( i = 0; i < iMeshCount; i++ )
                                {
                                        pMesh = pMeshCache->getMeshByIndex( i );
                                        if ( pMesh )
                                                pMeshCache->removeMesh( pMesh );
                                }
 
                                if ( iMl < 10 && pMeshCache->getMeshCount() )
                                {
                                        iMl++;
                                        goto dml;
                                }
                        }
                        else
                        {
                                ASSERT( false );
                                return -1;
                        }
                        m_pMeshCube = NULL;                             // Has now been deleted
                }
 
 
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm

Re: Huge memory leak when restarting Irrlicht...

Postby CuteAlien » Mon Mar 12, 2012 6:39 pm

Problem is this line:
cpp Code: Select all
 
pMesh = pMeshCache->getMeshByIndex( i );
 


If you remove the first element - the next element has now index 0.
So what you should use here is not i but 0, then all elements will be removed. If you start removing from the back it will be even faster - and then you can use an index (just be careful not to use an unsigned index and check for >= 0 ).
IRC: #irrlicht on irc.freenode.net
My patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Games with Irrlicht: http://www.irrgheist.com/
News: http://www.reddit.com/r/irrlicht/
User avatar
CuteAlien
Admin
 
Posts: 5358
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Huge memory leak when restarting Irrlicht...

Postby robmar » Mon Mar 12, 2012 6:52 pm

:oops: Oh no.... not again, I made that mistake last week too!!

So thanks, um, just popping out to jet wash my neurons!! :oops:

This is the new code, removing from back to avoid causing the internal copy-down:

cpp Code: Select all
 
        u32 uMeshCount = pMeshCache->getMeshCount();
                        for ( u32 ui = uMeshCount; ui > 0; ui-- )
                        {
                                pMesh = pMeshCache->getMeshByIndex( ui-1 );
                                if ( pMesh )
                                        pMeshCache->removeMesh( pMesh );
                        }
 
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm

Re: Huge memory leak when restarting Irrlicht...

Postby hendu » Tue Mar 13, 2012 2:05 pm

Just curious, why not use ->clear()?
hendu
 
Posts: 1555
Joined: Sat Dec 18, 2010 12:53 pm

Re: Huge memory leak when restarting Irrlicht...

Postby robmar » Tue Mar 13, 2012 3:31 pm

Good question... if a mesh has more than one grab on it, clear won´t delete it, and then it won´t clear up the array allocations. So I am trying to do this in a controlled way, and handle multiple grabs.
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm

Re: Huge memory leak when restarting Irrlicht...

Postby serengeor » Tue Mar 13, 2012 3:34 pm

You shouldn't have it grabbed multiple times in the first place before clearing, cause if it is grabbed by some class, that class expects it to still be available until it drops it.
Working on game: Marrbles (Currently stopped).
User avatar
serengeor
 
Posts: 1695
Joined: Tue Jan 13, 2009 7:34 pm
Location: Lithuania

Re: Huge memory leak when restarting Irrlicht...

Postby robmar » Tue Mar 13, 2012 4:19 pm

Yes of course, but the thing is to know this has happened so the code can be fixed, which clear doesn´t report.
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm

Re: Huge memory leak when restarting Irrlicht...

Postby hendu » Tue Mar 13, 2012 4:22 pm

clear()
getMeshCount()
?
hendu
 
Posts: 1555
Joined: Sat Dec 18, 2010 12:53 pm

Re: Huge memory leak when restarting Irrlicht...

Postby robmar » Tue Mar 13, 2012 4:26 pm

yes, that works! I was just testing
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm

Re: Huge memory leak when restarting Irrlicht...

Postby robmar » Fri Nov 09, 2012 6:25 pm

I´ve also found a massive memory leak with the opengl driver even on the beta 1.8.0 driver, around 12+ MB on closing, which does not occur when using the D3D driver.

Win 7 32-bit, Irrlicht 1.7.2. through to 1.8.0 SVB 4309
robmar
 
Posts: 565
Joined: Sun Aug 14, 2011 11:30 pm

Re: Huge memory leak when restarting Irrlicht...

Postby hendu » Fri Nov 09, 2012 7:10 pm

1.8 final is out ;)
hendu
 
Posts: 1555
Joined: Sat Dec 18, 2010 12:53 pm

PreviousNext

Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 1 guest