Quantcast
Channel: MSDN Blogs
Viewing all articles
Browse latest Browse all 35736

Memory usage when is used .NET components

$
0
0
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();
        varDOTNET.SetValue('par');
        CLEAR(varDOTNET);
   END;

 

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 
 CallToFunction(‘par’);
…………

PROCEDURE CallToFunction@1(parameter@1170000001 : Text);
VAR
  varDOTNET@1170000000 : DotNet "'MemoryExample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.MemoryExample.DotNetObject";

        varDOTNET :=varDOTNET.DotNetObject();
        varDOTNET.SetValue(parameters);
        CLEAR(varDOTNET);

 

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



Viewing all articles
Browse latest Browse all 35736

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>