I have this code. The delete[] function (line 7 and 12) isn't freeing up memory assigned with Triangle3D *triangles = new Triangle3D[triangleCount] (line 17). My RAM usage is growing each time face->GetTriangles() is called. I'd be grateful for any assistance:
get rid of that hideous memory management
use std::vector instead
and run your code through valgrind to check for memory leaks
apart from that IntersectTriangle(rayPos, rayDir, closestHit, triangleIndexHit, triangle)
¿why is `triangle' a pointer there?
¿what's the purpose of `triangleIndexHit'?
get rid of that hideous memory management
use std::vector instead
1 2 3 4 5 6 7 8 9 10
std::vector<Triangle3D> triangles = face->GetTriangles();
int triangles_size = triangles.size();
for (int i = 0; i < triangles_size; i++)
{
if (IntersectTriangle(rayPos, rayDir, closestHit, triangles[i]))
{
triangleIndexHit = i;
returntrue;
}
}
Didn't work. My memory usage is still increasing.
and run your code through valgrind to check for memory leaks
I'm using windows, so I installed Dr. Memory instead. Couldn't make any sense of it.
I googled a bit and got some ideas, but no solution. According to some, calling delete doesn't necessarily mark the memory location as available to the OS for reclaiming. I need this part to clear up as it is being called continuously (while the app is idle). Any ideas?
A testcase consisting of randomly copy&paste'd bits of code that you thought were relevant can obviously not reproduce the problem. Worse, such testcases force your perception of the problem upon us, preventing us from taking a fresh look at it and making an unbiased analysis.
> it is being called continuously (while the app is idle)
the old idle is not idle trick
perhaps you should make the triangles less temporal then.
> I'm using windows, so I installed Dr. Memory instead. Couldn't make any sense of it.
haven't used that tool.
it should be something like
$ drmemory.exe -- c:/path/to/my/app args to my app
I couldn't fulfill point 6 because of the actual size of the code.
Couldn't make any sense of it.
I meant that the result I got from using the tool didn't point me to the cause.
perhaps you should make the triangles less temporal then.
Thanks ne555. I did that, and it led me to the solution. It turns out that Face3D inherits from Surface3D and was returning an array of Triangle3D objects which also inherits from Surface3D.
Duthomhas I didn't have to write my own memory manager and I'm pretty sure it was because of my bad code.