Memory issues loading in stl files as children entities

Everything DG Kernel: Technical discussions and issues
Post Reply
oliver_h
Posts: 1
Joined: Thu Feb 06, 2025 10:22 pm

Memory issues loading in stl files as children entities

Post 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!
Attachments
CSharp Example.zip
(59.31 KiB) Downloaded 295 times
VB6 Example.zip
(10.03 KiB) Downloaded 294 times
Prashant Kande
Posts: 86
Joined: Tue Jun 18, 2024 6:12 am

Re: Memory issues loading in stl files as children entities

Post by Prashant Kande »

Thank you for the great analysis, Oliver.
We have entered the problem into the system. It is in the queue.
Regards
Post Reply