DiscussionsIssue archiveOther usage issues

Archived discussion

How to clear the memory? Help, please!!!

Other usage issuesMon, 07/21/2008 - 17:4210 replies

Browse this forum
QuestionAuthor

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!

Discussion

10 archived replies

Posts are displayed in their archived order.

01Commenter-1

You should close the document before nullifying its handle. A document is stored statically in the session till you close it.

02Commenter-2

close the document? how? Doc.close()??i don't see any function like that in OCC. help

03Commenter-1

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().

04Author

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!!!

05Author

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();

}

06Author

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();
}

07Commenter-1

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.

08Commenter-3

Hello Sergey!
I'm having to deal with this issue also. Have you made any progress on finding what's going wrong?
Regards,
Commenter-3

09Commenter-3

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.

10Commenter-3

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.

Commenter-3