Memory leak in terrain\terrCollision.cc: 422 ?
by Duncan Gray · in Torque Game Engine · 01/25/2006 (9:20 pm) · 2 replies
My experemental memory leak catcher complains that this is a problem.
// Create a new convex.
TerrainConvex* cp = new TerrainConvex;
sTerrainConvexList.registerObject(cp);
convex->addToWorkingList(cp);
The bold line is the culprit.
registerObject just adds it to a linked list in collission/convex.cc
Also in collission/convex.cc is a garbage collection method to delete the above TerrainConvex
Is it possible that missions can end before all garbage collection is done etc?
Quote:
I've added a function to memory manager to produce a list of places where memory has been created but not destroyed.
I then started a mission, exited the mission, ran the function to get a list of things not destroyed after the mission.
// Create a new convex.
TerrainConvex* cp = new TerrainConvex;
sTerrainConvexList.registerObject(cp);
convex->addToWorkingList(cp);
The bold line is the culprit.
registerObject just adds it to a linked list in collission/convex.cc
void Convex::registerObject(Convex *convex)
{
convex->linkAfter(this);
}Also in collission/convex.cc is a garbage collection method to delete the above TerrainConvex
void Convex::collectGarbage()
{
// Delete unreferenced Convex Objects
for (Convex* itr = mNext; itr != this; itr = itr->mNext) {
if (itr->mReference.rLink.mNext == &itr->mReference) {
Convex* ptr = itr;
itr = itr->mPrev;
delete ptr;
}
}
}Is it possible that missions can end before all garbage collection is done etc?
About the author
#2
Since terrain collision is using a global convex list, it is never destroyed at the end of a mission... presumably when a new mission is started up, the old convex shapes would be removed by garbage collection, but in the meantime there is a pretty large memory leak...
I don't really have a solution as I don't think the terrain code knows when the mission has ended... If there is some way to let the terrain code know the mission has ended, simply deleting the sTerrainConvexList should suffice...
Stephane
03/17/2006 (4:46 pm)
I think this may be a bug. In most 'BuildConvex' functions, the 'new'ly created Convex is added to a convex list and that convex list is then destroyed when the object is destroyed.Since terrain collision is using a global convex list, it is never destroyed at the end of a mission... presumably when a new mission is started up, the old convex shapes would be removed by garbage collection, but in the meantime there is a pretty large memory leak...
I don't really have a solution as I don't think the terrain code knows when the mission has ended... If there is some way to let the terrain code know the mission has ended, simply deleting the sTerrainConvexList should suffice...
Stephane
Torque 3D Owner Eric Roberts
Take a look at any buildConvex method in Torque and you will see that to add a convex, it's first allocated (a la new) and then added to the working list. A nice brief example would be PhysicalZone::buildConvex().
The reason why I seriously doubt that this case is a bug is because if this particular instance causes a memory leak - then ALL of the objects that implement buildConvex create memory leaks (something your expermental memory leak detector didn't seem to find). But I suppose I could be mistaken.
In all likelyhood it's probably not a problem.
- Eric