It's quite similar to https://communities.bentley.com/products/programming/microstation_programming/f/microstation-programming---forum/201080/mstn-ce-u14-vba-and-com-interop-does-not-release-memory but this time it happens while accessing child elements.When I run this code and do 1Mio Runs, my memory does not get released:
CellElement element = comApp.ActiveModelReference.GetElementByID(elementId) as CellElement; for (int i = 0; i < nRuns; i++) { ElementEnumerator subElements = element.GetSubElements(); while (subElements.MoveNext()) { //... } }
My DGN only contained one Cell Element with 7 Shape Elements. Nothing fancy or special. I was able to exhaust all my RAM with this simple function. A DGN change did not released the memory either.I've tested this on 10.16.02.34 and 10.17.01.62 and both behaved the same.
Hi Jean-Pierre,
Jean-Pierre Hundhausen said:but this time it happens while accessing child elements.
it looks like a bug (reference counting not working right?) in COM API, so memory is not released.
I agree it looks like the same type of bug I reported in the mentioned post, but at different place.
Jean-Pierre Hundhausen said:When I run this code and do 1Mio Runs, my memory does not get released:
Can you try to the same with VBA? It can help to analyze whether the issue is in the code same for VBA and Interop (in COM code) or specifically in Interop library.
Jean-Pierre Hundhausen said:Calling element = null; does not change the outcome.
It typically does not help, because when ref counting does not work, it is not informed the variable is null or out of scope.
Jean-Pierre Hundhausen said:COM/Interop does not release memory
I recommend to prepare test case (your simple DGN) and VBA code (when it can be duplicated in VBA) and to create service ticket plus to share it also in this discussion.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
I've tried it with VBA with the Code below and same results. Switching DGNs also did not freed up the Memory.
Public Sub MemoryBenchmark() Dim elements As ElementEnumerator Set elements = ActiveModelReference.Scan Dim i As Long Do While elements.MoveNext Dim element As element Set element = ActiveModelReference.GetElementByID(elements.Current.ID) If (element.IsCellElement) Then Dim cellElement As cellElement Set cellElement = element.AsCellElement For i = 1 To 1000000 Dim subElements As ElementEnumerator Set subElements = cellElement.GetSubElements() Do While subElements.MoveNext Loop Next End If Loop End Sub
I added the DGN I used.
test_memory.dgn
Mit freundlichen Grüßen / Best regardsJean-Pierre Hundhausen
| AB_DATE Engineering Software | ab-date.de |
Jean-Pierre Hundhausen said:I've tried it with VBA...Dim element As element Set element = ActiveModelReference.GetElementByID(elements.Current.ID)
Dim element As element Set element = ActiveModelReference.GetElementByID(elements.Current.ID)
You've created a new reference to element. Why not simply...
element
Set element = elements.Current
Regards, Jon Summers LA Solutions
I'm not that fluent with VBA. I separated declaration of a variable with filling it. But it should be "As Element", same with "As CellElement". But this shouldn't make a big difference.
thank you for reporting this issue. This is also reproducible with different dgn/code examples and I have filed Bug # 1041608 to address this issue.
Best regards,
Artur
Answer Verified By: Jean-Pierre Hundhausen