Since days, I am trying to figure out my "allocation/deallocation" problem. Its simple: I have a class called "Mesh". This is used for my OpenGL stuff.
Pseudo class Mesh:
- std::vector<mathVector3> normals
- std::vector<mathVector3> coordinates
- std::vector<mathVector2> texture
- addVertex(mathVector3 _normals, mathVector3 _coordinates, mathVector2 _texture);
After I noticed that in my application are huge memory leaks, I began with debuging. For this, I wrote a "test application".
First I tried following (pseudo):
(breakpoint1) Mesh *TestMesh1 = new Mesh();
for(int i=0; i<100000; i++) TestMesh1 ->addVertex(mathVector3(0.0f), mathVector3(0.0f),mathVector2(0.0f));
(breakpoint2) while(1) break; // only for breakpoint
(breakpoint3) while(1) break; // only for breakpoint
Now my RAM values for each breakpoint:
breakpoint1: 12.500 MB
breakpoint2: 59.800 MB
breakpoint3: 12.800 MB
Thats a difference of 300 kb. So 300 kb isnt deallocated. So I looked for a solution in the internet and read that "std::vectors needs a workaround".
The workaround is, to implement a "FreeAll" function, with a Template and using std::vector´s method "swap()".
So I added "FreeAll()" in my "Mesh" deconstructor before calling "clear()".
I repeated my test with breakpoints:
Same Result. 300 kb isnt been deallocated.
I am kind of frustrated, cause I dont know any solution for this. I think I missed something.
Why its important for me?
Because my Application is a "CAD-Program" which constantly changes Meshes (old Mesh is being deleted, and the new one allocated).
This is not about "not deallocationg 300 kb". Its about using not only one Mesh instance, there are hundreds of instances. There are constant changes for most of those Meshes: deallocations and allocations.
After a while, my App is allocating several GBs of RAM.