As you know, .NET uses garbage collection for freeing memory. GC uses some complex algorithm as to when and how it does the job. It actually changes between .NET versions. From our point of view, it should be considered random.
Say, you have code
Code: Select all
void f()
{
int sz = EstimateMeshSize();
}
int EstimateMeshSize()
{
IModel_DG iModelStandalone = m_generator.Create<IModel_DG>();
iModelStandalone.Load("LargeMesh.stl");
int simplexCount;
// .... Access the mesh and assign simplexCount
return simplexCount;
}
It is not what is happening by default with pure .NET DGKC controls. GC does not release the memory immediately. Often this can be observed in PC's performance monitors. Sometimes the memory is released only when the application closes.
It often makes sense and should not be a concern. Why reduce performance if there is plenty of memory? We need to trust that GC is smart enough.
If you do prefer the memory to be release immediately, add GC.Collect(); line in your code like:
Code: Select all
void f()
{
int sz = EstimateMeshSize();
GC.Collect();
}
Happy coding