Memory leaks + fixes
by Chris Robertson · in Torque Game Engine · 10/29/2004 (1:19 pm) · 6 replies
While tracking down memory leaks in my own game, I have found the following 2 memory leaks which also exist in the current HEAD:
1. In interiorLMManager.cc, 'pBitmaps' is an array of arrays (see interiorInstance, line 1945), but only the outer array is deleted. After the for loop at line 423, add the following:
2. In shapeImage.cc, line 1817, a particle emitter is created, but if registerObject() fails, it will never be deleted. The registerObject() call fails for any state in the mounted image datablock which does not specify an emitter (such as CrossbowImage in starter.fps). The function 'startImageEmitter' should not even be called for such image states. To prevent this leak, just modify shapeImage.cc, line 1615:
There are also a number of other places where the return value of registerObject() is not checked. Each is a potential memory leak.
There should be a bounty for these sort of things! ;D
1. In interiorLMManager.cc, 'pBitmaps' is an array of arrays (see interiorInstance, line 1945), but only the outer array is deleted. After the for loop at line 423, add the following:
for(U32 j = 0; j < interiorInfo->mNumLightmaps; j++)
{
...
}
[b]delete [] pBitmaps[i]; // add this line[/b]2. In shapeImage.cc, line 1817, a particle emitter is created, but if registerObject() fails, it will never be deleted. The registerObject() call fails for any state in the mounted image datablock which does not specify an emitter (such as CrossbowImage in starter.fps). The function 'startImageEmitter' should not even be called for such image states. To prevent this leak, just modify shapeImage.cc, line 1615:
if (isGhost() && stateData.emitter)
There are also a number of other places where the return value of registerObject() is not checked. Each is a potential memory leak.
There should be a bounty for these sort of things! ;D
#2
10/30/2004 (8:44 am)
Fixed in trunk, thanks Chris.
#3
03/26/2005 (12:04 pm)
I like that bounty idea, thanks for the memleak fixes!
#4
03/27/2005 (5:01 am)
Can one include a little more code to fix the shapeImage problem? Can't seem to find the reference in my code. Probably due to my changes. :)
#5
03/28/2005 (11:12 am)
Thanks for the fixes.
#6
Chris is stating that what he listed is the fix for the shapeImage problem.
The current line 1615 in v1.3 is
Chris says that this should be
03/28/2005 (11:50 am)
@WendellChris is stating that what he listed is the fix for the shapeImage problem.
The current line 1615 in v1.3 is
if (isGhost())
Chris says that this should be
if (isGhost() && stateData.emitter)
Associate Kyle Carter