
Mon, 07/21/2008 - 17:42
Hi,
I am using OCC to process a set of step files. However I noticed that OCC objects never get destroyed in the memory.
Calling .Nullify() method just detaches object from the handle.
This is a very seriouis issue for me since I need to actually delete all the object associated with the current step file before I can go ahead with the next one.
I use the following code:
Handle(TDocStd_Document) Doc;
STEPCAFControl_Reader reader ;
XCAFApp_Application::GetApplication()->NewDocument("MDTV-XCAF",Doc);
IFSelect_ReturnStatus readstat = reader.ReadFile("C:\\STP_Samples\\sample214.STEP");
reader.SetColorMode(true);
reader.SetNameMode(true);
reader.SetLayerMode(true);
reader.Transfer(Doc);
Doc.Nullify();
After calling Transfer() function a lot of memory gets allocated, but its never cleared, never returned neither to OS nor to OCC.
Doc.Nullify() does not actually erase the objects, just detaches them!!!
I tried changing both MMGT_OPT and MMGT_CLEAR. No matter what I do memory is never released!
Is any function available which will actually destroy the objects?
Am I missing something here?
Please, help!
Mon, 07/21/2008 - 18:20
You should close the document before nullifying its handle. A document is stored statically in the session till you close it.
Mon, 07/21/2008 - 18:24
close the document? how? Doc.close()??i don't see any function like that in OCC. help
Mon, 07/21/2008 - 18:50
It is the method of application:
void TDocStd_Application::Close(const Handle(TDocStd_Document)& aDoc);
In the code of Sergey the access to application is provided by calling XCAFApp_Application::GetApplication().
Mon, 07/21/2008 - 19:32
Thanks a lot!
I tried it and it helped a little bit, but still not all the memory is released.
Also I cant call it in the loop, seems like reader itself is a static object. Correct me if I am wrong.
Is anyway to destroy the reader object itself?
I am missing something again.
Please advice!!!
Mon, 07/21/2008 - 20:11
Alright, here is the code I run.
The memory keeps increasing dramatically.
What can be wrong? Just open close document should not constantly increase the memory usage!
Please Let men know if I missed some close/clear statement or anything!!! Any help is highly appreciated!!!
for (int i=0; i<500;i++)
{
STEPCAFControl_Reader reader;
Handle(TDocStd_Document) Doc;
reader.SetColorMode(true);
reader.SetNameMode(true);
reader.SetLayerMode(true);
IFSelect_ReturnStatus readstat = reader.ReadFile("C:\\STP_Samples\\sample214.STEP");
XCAFApp_Application::GetApplication()->NewDocument("MDTV-XCAF",Doc);
if(!reader.Transfer(Doc))
{
XCAFApp_Application::GetApplication()->Close(Doc);
Doc.Nullify();
return 1;
}
XCAFApp_Application::GetApplication()->Close(Doc);
Doc.Nullify();
}
Mon, 07/21/2008 - 20:13
Alright, here is the code I run.
The memory keeps increasing dramatically.
What can be wrong? Just open close document should not constantly increase the memory usage!
Please Let men know if I missed some close/clear statement or anything!!! Any help is highly appreciated!!!
for (int i=0; i<500;i++)
{
STEPCAFControl_Reader reader;
Handle(TDocStd_Document) Doc;
reader.SetColorMode(true);
reader.SetNameMode(true);
reader.SetLayerMode(true);
IFSelect_ReturnStatus readstat = reader.ReadFile("C:\\STP_Samples\\sample214.STEP");
XCAFApp_Application::GetApplication()->NewDocument("MDTV-XCAF",Doc);
if(!reader.Transfer(Doc))
{
XCAFApp_Application::GetApplication()->Close(Doc);
Doc.Nullify();
return 1;
}
XCAFApp_Application::GetApplication()->Close(Doc);
Doc.Nullify();
}
Tue, 07/22/2008 - 13:00
I have no idea any more. It is needed to use some tool for dynamic memory checking to know where the memory is not released.
Mon, 11/24/2008 - 10:40
Hello Sergey!
I'm having to deal with this issue also. Have you made any progress on finding what's going wrong?
Regards,
Dirk
Wed, 03/25/2009 - 08:45
Before closing the document I call ForgetAllAttributes on all of the xcafdoc tools (XCAFDoc_ShapeTool, XCAFDoc_LayerTool, ...). Then all or at least most of the memory was released. I tested this with the IGESCAFControl_Reader on some files in a loop.
I'm not sure what is happening.
Thu, 03/26/2009 - 17:40
Just call aDocument->Main().ForgetAllAttributes() before XCAFApp_Application::GetApplication()->Close( aDocument ). This gives the same result as above. In this case valgrind reports "still reachable" leaks only. When omitting ForgetAllAttributes valgrind shows many "definite" leaks, e.g. in TNaming_Builder::Generated called from XCAFDoc_ShapeTool::addShape ... . I am giving up trying to understand where the memory allocated in TNaming_Builder::Generated should be freed.
Dirk