Huge memory leak when restarting Irrlicht...
Re: Huge memory leak when restarting Irrlicht...
Sounds good, whats the function call to get the total count?
Re: Huge memory leak when restarting Irrlicht...
We're talking about maybe adding a feature, so obviously there can't be a function call yet.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Huge memory leak when restarting Irrlicht...
So I could just add a global counter and increment it in the grab function..
Re: Huge memory leak when restarting Irrlicht...
yeah, that's the idearobmar wrote:So I could just add a global counter and increment it in the grab function..
Working on game: Marrbles (Currently stopped).
Re: Huge memory leak when restarting Irrlicht...
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?
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...
Problem is this line:
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 ).
Code: Select all
pMesh = pMeshCache->getMeshByIndex( i );
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.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Huge memory leak when restarting Irrlicht...
Oh no.... not again, I made that mistake last week too!!
So thanks, um, just popping out to jet wash my neurons!!
This is the new code, removing from back to avoid causing the internal copy-down:
So thanks, um, just popping out to jet wash my neurons!!
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...
Just curious, why not use ->clear()?
Re: Huge memory leak when restarting Irrlicht...
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...
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).
Re: Huge memory leak when restarting Irrlicht...
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...
clear()
getMeshCount()
?
getMeshCount()
?
Re: Huge memory leak when restarting Irrlicht...
yes, that works! I was just testing
Re: Huge memory leak when restarting Irrlicht...
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
Win 7 32-bit, Irrlicht 1.7.2. through to 1.8.0 SVB 4309
Re: Huge memory leak when restarting Irrlicht...
1.8 final is out