Memory Leak when using STEPCAFControl_Reader

Hello,

I am encountering memory leak in the following function as pointed out by valgrind:

Handle(TDocStd_Document) ReadStep(std::string filename){

    STEPCAFControl_Reader Reader;

    // Create XDE document.
    Handle(XCAFApp_Application) app = XCAFApp_Application::GetApplication(); 
    BinXCAFDrivers::DefineFormat(app);
    Handle(TDocStd_Document) doc;
    app->NewDocument("BinXCAF", doc);

    // Read CAD and associated data from file
    IFSelect_ReturnStatus outcome = Reader.ReadFile(filename.c_str());
    //

    if ( outcome != IFSelect_RetDone )
    {
      app->Close(doc);
      return nullptr;
    }

    if ( !Reader.Transfer(doc) )
    {
      app->Close(doc);
      return nullptr;
    }
    
    return doc;
}

Am I doing something wrong? I am a beginner to C++. Any help is greatly appreciated.

Best Regards
Kaiwen

Dmitrii Pasukhin's picture

Hello,

How you clarify that it is a leak? Could you send a valgrid report?

Best regards, Dmitrii.

Kaiwen He's picture

Hello,

I have attached the valgrind output.

Best Regards
Kaiwen

Attachments: 
Dmitrii Pasukhin's picture

Unfortunatelly you using occt 7.4 (4 year old release).

Probably you can't impact on it. It is internal problem. I will check the same code on 7.8.0 with valgrind.

Best regards, Dmitrii.

Kaiwen He's picture

Thank you for your effort and fast answer.

I am looking forward to your response.

Best Regards
Kaiwen

Kaiwen He's picture

Hello Dmitrii,

have you found out anything?

Also if I want to upgrade my OCCT version how do I go about it?
I have installed the 7.4 version via cmake on my system. Is there a "make uninstall" option?

Best Regards
Kaiwen

Dmitrii Pasukhin's picture

I will plan to check it a little later. But probably it is resolved on last version.

Unistall is not possible in native cmake-make env.

Best regards, Dmitrii.

gkv311 n's picture

At least one related issue #0031075 has been fixed in OCCT 7.5. So it makes sense to check later releases. Note that STEP translator uses some global objects, which are not automatically released, but reused on next translations.

Kaiwen He's picture

Hello,

I have updated OCCT to version 7.7 (which is the latest release as I can see), but unfortunately the problem still persists.

I have attached a valgrind report using version 7.7

Also, I noticed the memory lost depends heavily on the STEP file read using STEPControl_Reader

Best Regards
Kaiwen

Attachments: 
gkv311 n's picture

Valhrind is great for deep checks, but could you provide a real-world use case with repetitive STEP imports resulting in memory leaks and amount of them? (Kilobytes, megabytes?). Does memory leak noticable for entire application workflow?

Dmitrii Pasukhin's picture

The report describes issues with buffered global static variables allocation in SControl_Controller::Customise, STEPEdit_EditContext, Interface_Staticand similar that is not a leaks. But just an artifacts of old DE way. We planned to update this, but it is not a leak. This "leak" will not so impact on more then one read process.

But thank you. We will take more attention on this.

Best regards, Dmitrii.