For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

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

Sergey's picture
Forums: 

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!

Bearloga's picture

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

Wi Wi Wi's picture

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

Bearloga's picture

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

Sergey's picture

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

Sergey's picture

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 {

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

}

Sergey's picture

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

Bearloga's picture

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.

Dirk B's picture

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

Dirk B's picture

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.

Dirk B's picture

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

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.