30MB Memory Leak or what is wrong here?

We recieved indications of memory leak problems from one of our customers and simplified the code as shown below. After the for-loop memory increased about 30MB! Our Question is, if its a leak or just the wrong usage of the occ-library-function.

Best regards
Marcel Keller

#include "TopoDS_Shape.hxx"
#include "TopoDS_Solid.hxx"
#include "BRepPrimAPI_MakeBox.hxx"
#include "BRepAlgoAPI_Cut.hxx"

int main(int argc, char* argv[])
{
TopoDS_Solid box1;
TopoDS_Solid box2;
for (int i=0; i box1 = BRepPrimAPI_MakeBox(100,100,100);
box2 = BRepPrimAPI_MakeBox(50,50,50);
BRepAlgoAPI_Cut cutOperation(box1, box2);
}
return 0;
}

Marcel Keller's picture

Supplementary Information: We are using OCC 5.2.

Mikael Aronsson's picture

Hi !

OCC use it's own memory allocator that allocates big chunks of memory and it may take time before this memory is released again so it may no be a leak at all, if you continue to run the loop does it allocates even more memory ir does it stay at 30MB ? if it do you can assume that this is normal behavior.

Mikael

Marcel Keller's picture

Dear Mikael

After running the loop 10000 times the memory increases about 252MB.

Marcel Keller

JeanmiB's picture

Hello Marcel,

I made a test on OCC4.0 (my other computer with OCC5.2 is not available for the moment).
I didn't notice any increase in memory during the loop test (even with the 10000 times loop). Moreover the memory remains almost constant during the loop (which looking at your code seems logical to me).

So I guess that something wrong with OCC5.2. Memory Leak ? Perhaps, I'll try another test later on OCC5.2.

Regards

Stephane Routelous's picture

Hi Marcel,

I ran your test with OCC5.2 (compiled in debug) on Windows 2000 with VC6.0 SP5 and Boundchecker (for the memory leaks ) but with only 10 loops (because it is too slow)
and the result is :
Boundchecker detects memory leaks :
(sorry for the formating, but I cannot get something better)

Type Quantity Total (bytes) Allocation Location Sequence

Total Memory Leaks 333 973,256

Memory Leak 333 973,256

Leak exiting program 41 656 new - [Standard_MyMapOfTypes.cxx, line 52 (TKernel.dll)]

Leak exiting program 1 16 new - [Standard_MyMapOfTypes.cxx, line 52 (TKernel.dll)] 29
Memory Leak Exiting Program: Address 0x5B53290 (16) allocated by calloc.

Call Stack At Allocation
new U:/OpenCASCADE5.2/ros/src/Standard/Standard_MyMapOfTypes.cxx 52
AddFromType U:/OpenCASCADE5.2/ros/src/Standard/Standard_MyMapOfTypes.cxx 152
Add U:/OpenCASCADE5.2/ros/src/Standard/Standard_Type.cxx 66
Standard_Type U:/OpenCASCADE5.2/ros/src/Standard/Standard_Type.cxx 256

(...)

Type Quantity Total (bytes) Allocation Location Sequence

Leak exiting program 289 964,360 MAllocate - [Standard.cxx, line 433 (TKernel.dll)]

Leak exiting program 1 424 MAllocate - [Standard.cxx, line 433 (TKernel.dll)] 35
Memory Leak Exiting Program: Address 0x5B53520 (424) allocated by calloc.

Call Stack At Allocation
MAllocate U:/OpenCASCADE5.2/ros/src/Standard/Standard.cxx 433
Allocate U:/OpenCASCADE5.2/ros/inc\Standard_Allocate.lxx 14
BeginResize U:/OpenCASCADE5.2/ros/src/TCollection/TCollection_BasicMap.cxx 67
ReSize U:/OpenCASCADE5.2/ros/inc\TCollection_IndexedDataMap.gxx 76

(...)

Type Quantity Total (bytes) Allocation Location Sequence

Leak exiting program 1 4,040 BeginResize - [Standard_BasicMap.cxx, line 84 (TKernel.dll)] 358
Memory Leak Exiting Program: Address 0x83CB1E8 (4040) allocated by calloc.

Call Stack At Allocation
BeginResize U:/OpenCASCADE5.2/ros/src/Standard/Standard_BasicMap.cxx 84
ChangeSize U:/OpenCASCADE5.2/ros/src/Standard/Standard_MyMapOfTypes.cxx 71
AddFromType U:/OpenCASCADE5.2/ros/src/Standard/Standard_MyMapOfTypes.cxx 157
Add U:/OpenCASCADE5.2/ros/src/Standard/Standard_Type.cxx 66

Leak exiting program 1 4,040 BeginResize - [Standard_BasicMap.cxx, line 86 (TKernel.dll)] 359
Memory Leak Exiting Program: Address 0x83CC1F8 (4040) allocated by calloc.

Call Stack At Allocation
BeginResize U:/OpenCASCADE5.2/ros/src/Standard/Standard_BasicMap.cxx 86
ChangeSize U:/OpenCASCADE5.2/ros/src/Standard/Standard_MyMapOfTypes.cxx 71
AddFromType U:/OpenCASCADE5.2/ros/src/Standard/Standard_MyMapOfTypes.cxx 157
Add U:/OpenCASCADE5.2/ros/src/Standard/Standard_Type.cxx 66

Leak exiting program 1 160 _onexit - [onexit.c, line 104 (occmemleak.exe)] 361
Memory Leak Exiting Program: Address 0x8381010 (160) allocated by _realloc_dbg.

Call Stack At Allocation
_onexit onexit.c 104
atexit onexit.c 141
numpunct * __cdecl std::_Tidyfac >::_Save c:\program files\microsoft visual studio\vc98\include\xlocale 138
numpunct const & __cdecl std::use_facet c:\program files\microsoft visual studio\vc98\include\xlocale 168

HTH,

Stephane
http://www.exotk.org

Marcel Keller's picture

Hi Stephane

Thanks a lot for your help.

Marcel

JeanmiB's picture

Hello Marcel,

You can try to set the environment variable MMGT_OPT=1, before running your program.
Doing so I didn't notice any increase in memory.

Regards.

Jean Michel

Marcel Keller's picture

Hi Jean

I tried to set MMGT_OPT=1 but nothing changed. I also tried to change environment variables like MMGT_THRESHOLD, MMGT_NBPAGES,....

By the way, I'm working with Windows 2000, Visual C++ 6.0 SP5.
Marcel

Mehdi's picture

Try this :
int main(int argc, char* argv[])
{
TopoDS_Solid box1;
TopoDS_Solid box2;
for (int i=0; i<1000; i++){
box1 = BRepPrimAPI_MakeBox(100,100,100);
box2 = BRepPrimAPI_MakeBox(50,50,50);
BRepAlgoAPI_Cut cutOperation(box1, box2);
box1.Nullify();
box2.Nullify();
}
return 0;
}

Open CASCADE Support Team's picture

Dear Mr. Keller,

Thank you for reporting this problem in Open CASCADE Technology!

We are pleased to inform you that the problem you reported has been registered as bug with reference number OCC7287 "Problem of Memory Leak".
By the moment, the fix for this problem has been successfully produced and tested for non-regression. It will appear in the following public version of Open CASCADE Technology.

We remind to all members of the Community that we value your efforts and we are always glad to receive your helpful contributions.

Yours sincerely,
Open CASCADE Support Team