Microsoft Dynamics 365 Blog
We already had few support request where NAV developers see big memory consumption increase when using .NET component.
Especially when method is inside some loop.
Like in this sample:

  FOR count := 1 TO 10000000 DO BEGIN
        varDOTNET :=varDOTNET.DotNetObject();


Even it looks like we create variable and then clear it – we can see continues memory usage increase in windows task manager.
But this is not “memory leak” this is how NAV is managing memory. If you start process again then memory usage decrease and increase to the same number.
So only during processing there could be issue that few users running the same code comes to memory limits.
Resolution is to transfer .NET method execution to local function

 FOR count := 1 TO 10000000 DO 

PROCEDURE CallToFunction@1(parameter@1170000001 : Text);
  varDOTNET@1170000000 : DotNet “‘MemoryExample, Version=, Culture=neutral, PublicKeyToken=null’.MemoryExample.DotNetObject”;

        varDOTNET :=varDOTNET.DotNetObject();


Also here are other coding ways where you can transfer part DotNet variable execution to functions. But it is always more effective transfer execution to function where “garbage collector” can make his job faster and more effective.


These postings are provided “AS IS” with no warranties and confer no rights. You assume all risk for your use.

Gedas Busniauskas

Microsoft Lithuania
Microsoft Customer Service and Support (CSS) EMEA

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!