Page 1 of 1

Memory issues loading in stl files as children entities

Posted: Thu Feb 06, 2025 10:53 pm
by oliver_h
Hello,

I'm trying to add a stl file to an existing model as a single component, with the entities of the stl file as the component's children.

To do this, I follow the following steps:
  1. Create standaloneModel and componentEntity via an objectGenerator.Create("iModel_DG") and "iEntity_DG"
  2. Load the stl file into the standaloneModel via .Load(filename)
  3. Get the standaloneModel's entity array, and add it to the componentEntity via .Add(iEntityArray,-1)
  4. Add the componentEntity to the main model via m_iModel.AddEntity(componentEntity)
Which seems to give the desired result. However, if I then remove the geometry via m_iModel.RemoveAll(true) or by deleting it in the model explorer, the geometry will disappear, but the memory consumption doesn't go down in the resource monitor / task manager. Additionally, trying to delete one of the Children of the component entity via the model explorer causes the whole program to crash.

If I import the stl directly to the main model via m_iModel.Load(filename) and then delete it, it seems to be fine. If the stl file into a standalone model, and then add the entity array to the main model (instead of an intermediate componentEntity), it seems to release most but not all of the memory.

Attached are two projects I've been testing. The issue seems to appear in both. (Although, the model explorer doesn't seem to work in the C Sharp version at all.) I've tried various permutations of setting objects = nothing / null, as well as calling .RemoveAll() or .Clear on the standalone models etc.
To reproduce it - launch the application and click the Import (Component) Button. It should load the stl file in the way described above. Clicking the clear button should clear the geometry, but the memory stays allocated. Any ideas?

The attached projects require a stl file to load, which can be downloaded here: https://drive.google.com/file/d/1GZtJUN ... sp=sharing if the link doesn't work, I believe any stl file that loads into multiple meshes should be equivalent

An example of the C Sharp code that I'm trying is:

Code: Select all

private void cmdImportComp_Click(object sender, EventArgs e)
{
    IModel_DG iModelStandalone;
    IEntityArray_DG iArrayEnt;
    IObjectGenerator_DG gen = m_iModel.Query<IObjectGenerator_DG>();
    IDictionary_DG MyDictionary;
    IEntity_DG MyComponentEntity;

    MyDictionary = gen.Create<IDictionary_DG>();
    MyDictionary.SetBool("SeperateObjects", true);


    iModelStandalone = gen.Create<IModel_DG>();
    MyComponentEntity = gen.Create<IEntity_DG>();

    iModelStandalone.Load(txtFilePath.Text);

    iArrayEnt = iModelStandalone.GetEntityArray(false);

    MyComponentEntity.Add(iArrayEnt, -1);
    MyComponentEntity.Name = "Component";

    for (int i = 0; i < MyComponentEntity.GetChildCount(); i++)
    {
        MyComponentEntity.GetChildAt(i).Name = "Child_" + i.ToString();
    }

    m_iModel.AddEntity(MyComponentEntity);
    m_iView.Reset(true, true);
    m_dgkc.UpdateView();

}

Thanks!

Re: Memory issues loading in stl files as children entities

Posted: Sat Feb 08, 2025 8:07 pm
by Prashant Kande
Thank you for the great analysis, Oliver.
We have entered the problem into the system. It is in the queue.
Regards

Re: Memory issues loading in stl files as children entities

Posted: Mon Mar 17, 2025 1:42 pm
by TheLeePiper
Can you please advise status of this memory issue? We are hitting restrictions and would like to know if you anticipate a near-term solution. Thanks!

Re: Memory issues loading in stl files as children entities

Posted: Tue Mar 18, 2025 1:45 am
by Prashant Kande
Sorry for the lack of response.

We have put this in for the v7.3. It is unsafe to fix the memory leaks in v7.2. Sometimes the fix causes a crash. It is a fine line between a leak or a crash. Leaks are safer.

So, the decision was to put it into 7.3. This way it will go through lots more testing.

Release of v7.3 is not expected until September. More likely it will be around November.

Re: Memory issues loading in stl files as children entities

Posted: Wed Apr 09, 2025 8:21 am
by Prashant Kande
We have started to look into this.

This should not matter for the problem, just in case:
In your code MyDictionary is not used. You must have meant
iModelStandalone.LoadEx(txtFilePath.Text, MyDictionary);

And a typo in the MyDictionary.SetBool("SeperateObjects", true);

Re: Memory issues loading in stl files as children entities

Posted: Fri Apr 11, 2025 12:30 pm
by oliver_h
Thanks for catching that - I double checked and as you mentioned it didn't seem to change the underlying problem.

One interesting thing (which may not be related) I ran into: When running the code with SeparateObjects, the tree view in the model explorer contains one root node named "Component", with two child nodes named "Child_0" and "Child_1" (as you'd expect). If in the model explorer you delete Child_0 and then Child_1 they delete as expected (although without freeing memory). However, if you delete Child_1 while there is still a Child_0, the program crashes with the following message:
Exception thrown at 0x00000000064E261F (kcgme64.dll) in MemTests.exe: 0xC0000005: Access violation reading location 0x0000000000000268.

Re: Memory issues loading in stl files as children entities

Posted: Sun Apr 13, 2025 8:36 pm
by Prashant Kande
We will look at it shortly as well.
Thanks for reporting