Page 2 of 3

Re: Huge memory leak when restarting Irrlicht...

Posted: Sat Mar 10, 2012 2:55 pm
by robmar
Sounds good, whats the function call to get the total count?

Re: Huge memory leak when restarting Irrlicht...

Posted: Sat Mar 10, 2012 4:45 pm
by CuteAlien
We're talking about maybe adding a feature, so obviously there can't be a function call yet.

Re: Huge memory leak when restarting Irrlicht...

Posted: Sat Mar 10, 2012 5:33 pm
by robmar
So I could just add a global counter and increment it in the grab function..

Re: Huge memory leak when restarting Irrlicht...

Posted: Sat Mar 10, 2012 6:06 pm
by serengeor
robmar wrote:So I could just add a global counter and increment it in the grab function..
yeah, that's the idea

Re: Huge memory leak when restarting Irrlicht...

Posted: Mon Mar 12, 2012 4:48 pm
by robmar
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?

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
                }
 
 

Re: Huge memory leak when restarting Irrlicht...

Posted: Mon Mar 12, 2012 6:39 pm
by CuteAlien
Problem is this line:

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 ).

Re: Huge memory leak when restarting Irrlicht...

Posted: Mon Mar 12, 2012 6:52 pm
by robmar
: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:

Code: Select all

 
        u32 uMeshCount = pMeshCache->getMeshCount();
                        for ( u32 ui = uMeshCount; ui > 0; ui-- )
                        {
                                pMesh = pMeshCache->getMeshByIndex( ui-1 );
                                if ( pMesh )
                                        pMeshCache->removeMesh( pMesh );
                        }
 

Re: Huge memory leak when restarting Irrlicht...

Posted: Tue Mar 13, 2012 2:05 pm
by hendu
Just curious, why not use ->clear()?

Re: Huge memory leak when restarting Irrlicht...

Posted: Tue Mar 13, 2012 3:31 pm
by robmar
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.

Re: Huge memory leak when restarting Irrlicht...

Posted: Tue Mar 13, 2012 3:34 pm
by serengeor
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.

Re: Huge memory leak when restarting Irrlicht...

Posted: Tue Mar 13, 2012 4:19 pm
by robmar
Yes of course, but the thing is to know this has happened so the code can be fixed, which clear doesn´t report.

Re: Huge memory leak when restarting Irrlicht...

Posted: Tue Mar 13, 2012 4:22 pm
by hendu
clear()
getMeshCount()
?

Re: Huge memory leak when restarting Irrlicht...

Posted: Tue Mar 13, 2012 4:26 pm
by robmar
yes, that works! I was just testing

Re: Huge memory leak when restarting Irrlicht...

Posted: Fri Nov 09, 2012 6:25 pm
by robmar
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

Re: Huge memory leak when restarting Irrlicht...

Posted: Fri Nov 09, 2012 7:10 pm
by hendu
1.8 final is out ;)