AL icon indicating copy to clipboard operation
AL copied to clipboard

Memory Leak

Open jvincke opened this issue 7 years ago • 18 comments

Describe the bug Within a project with around 600 objects (converted from C/AL to AL) we open e.g. each tableextension object one by one and fix remaining issues. For instance we modfiy the tableextension object name. After a while, like 30 opened and closed files, the memory consumption of the process Microsoft.Dynamics.Nav.EditorServices.Host exceeds 2GB. And it goes on and on. It appears that opening a file -obviously- takes up memory, but closing the file does not release the memory in use.

In order to exclude that the error arises from another VS Code Extension, I deactivated all other extensions, except AL Language and the German Language Pack.

To Reproduce Steps and/or AL code to reproduce the behavior:

  1. Create a project with a reasonable high amount of tableextension objects (e.g. 100)
  2. Open, modify, save and close each file one by one
  3. While doing step 2 monitor memory consumption of Visual Studio Code within Task Manager

Expected behavior Free up memory when the object is closed.

Screenshots Task Manager after opening 1st file: https://pasteboard.co/I8zFiQH.png Task Manager after opening 5th file: https://pasteboard.co/I8zFTFs.png Task Manager after opening 10th file: https://pasteboard.co/I8zG8eg.png Task Manager after opening 20th file: https://pasteboard.co/I8zGirA.png

Versions:

  • AL Language: 3.0.115791
  • Business Central: irrelevant, but in my case build 13.0.24623.0 is running on my localhost

jvincke avatar Apr 04 '19 12:04 jvincke

The memory allocation depends on many things. When editing source files the language compiler is constantly running in the background to provide diagnostic information (errors and warnings).

The language service is written in C# and the the garbage collection of memory may not happen immediately. You may have to wait for a while before the memory are released.

That said, we have recently found and fixed a couple of minor leaks, but not it didn't make it to the April release.

I noticed that your are using the Insider version of VsCode, do you see that same for the released version?

esbenk avatar Apr 05 '19 07:04 esbenk

I cannot confirm that the c# garbage collection triggers at any time, because I noticed it after working half a day in a large project. I noticed the problem as my workstation slowed down. I checked Task Manager and VS Code / AL Language ate up my entire available memory (6.5GB at that point). I would guess that the variables used are not discarded. Then no effect is expected from the garbage collection.

I usually do not work with VS Code Insiders. I noticed this behavior with the stable version and I switched to the Insiders build to test if the problem exists there too.

jvincke avatar Apr 05 '19 12:04 jvincke

As I mentioned we have fixed some minor leaks after the April release and maybe that is what you see.

It is an area we have focus on, but also very hard to investigate.

esbenk avatar Apr 05 '19 12:04 esbenk

We have the same issue here, the following screenshot is from a collegue: image The Problem here is that at some point you are not able to run the docker containers any more! That is a real problem.

The memory requirement can go insanly high when using local docker development with vscode eating up that much memory. Even regular Visual Studio with Resharper does not eat that much (which is a real resource hog).

If you have any fixes to the gc then you should consider to release that for the stable asap...

marknitek avatar Apr 18 '19 06:04 marknitek

Facing similar issues over here as well. When trying to convert (part of) our solution and loading the objects in VSCode (only one al file is opened in the editor), VScode eats almost all CPU/memory. Project consists of 5132 al objects, with 845 errors and 219 warnings (CodeAnalysis is not activated)

cpu

image

No real steps to reproduce, just opening VSCode already make my system to really slow down ... Any other info I can share to help you find the cause? In the meantime, we're awaiting the post April fix...

fvet avatar Apr 19 '19 20:04 fvet

Depending on your machine, it will take a minute or two (for your project size) for the initial full compilation to complete. In that period there will be constant high cpu load. That is expected.

esbenk avatar Apr 23 '19 06:04 esbenk

CPU load is not an issue. Memory usage is an issue since it can prevent container start for example...

marknitek avatar Apr 23 '19 07:04 marknitek

image

shashiBssi avatar Jul 17 '19 14:07 shashiBssi

Try to deactivate the code analysis in background. You have to writte this in your settings.json

"al.backgroundCodeAnalysis": false

AitorLD avatar Jul 18 '19 07:07 AitorLD

Try with the below settings: "editor.codeLens": false, "al.enableCodeAnalysis": false,

kalberes avatar Jul 22 '19 17:07 kalberes

To reduce memory consumption further during publishing and full build (Ctrl+Shift+B), use "al.incrementalBuild": true . We have addressed the major performance issues and you can benefit from them by trying the latest developer preview from https://freddysblog.com/2019/07/31/preview-of-dynamics-365-business-central-2019-release-wave-2/

atoader avatar Aug 09 '19 11:08 atoader

same here. two code cops (web and ui), approx 1200 Objects with 866 Problems (only warning and Information) memory consumption makes VSC almost unusable (worst thing until now 24 GB used by Microsoft.Dynamics.Nav.EditorServices.Host out of 32). AL Version 3.0.152816

KristofKlein avatar Aug 19 '19 09:08 KristofKlein

same here. two code cops (web and ui), approx 1200 Objects with 866 Problems (only warning and Information) memory consumption makes VSC almost unusable (worst thing until now 24 GB used by Microsoft.Dynamics.Nav.EditorServices.Host out of 32). AL Version 3.0.152816

Switch to 4.0.152993 - a bit better --- while coding have not seen more than 8 GB in usage...while compile it goes above 12 GB and drops again after that... but code cops are so slow ... If I change just a single character in a file all code cops results for that file are disappearing until i stop typing and wait for 10 seconds ...

KristofKlein avatar Aug 20 '19 08:08 KristofKlein

Are you also using the incremental build setting that I mentioned above, that should reduce the memory consumption of the full build to under 8 GB? We are aware that the performance of cops is not ideal for large projects and we have it on our backlog to improve it.

atoader avatar Aug 20 '19 08:08 atoader

Are you also using the incremental build setting that I mentioned above, that should reduce the memory consumption of the full build to under 8 GB? We are aware that the performance of cops is not ideal for large projects and we have it on our backlog to improve it.

well I don't mind about the build RAM usage....for me it is the solution just gets unusable over time and forces me to restart it ... (at the moment I have not done ANY build with the code that I have) only removing warnings and make my code clean. so on 4.0 it also goes up and up and up : image

and thats after 30 minutes of using it ...

KristofKlein avatar Aug 20 '19 09:08 KristofKlein

and up image

KristofKlein avatar Aug 20 '19 09:08 KristofKlein

Yes it is very annoying... Ctrl+shift+p reload window every now and then helps but anything above 8gb is just unusable tbh...

marknitek avatar Aug 20 '19 10:08 marknitek

It seems that we have a memory leak in one of the code cops. For the moment, I suggest disabling code analysis and running them as part of your CI/CD pipeline and only enabling it when needed.

atoader avatar Aug 28 '19 08:08 atoader