New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak #107999
Comments
I found this interesting -- https://chromium.googlesource.com/chromium/src.git/+/master/docs/memory/key_concepts.md |
//cc @deepak1556 |
|
Another observation is that this isn't really related to large files. This is a general memory leak. I can reproduce this by opening several 5-10MB text files and see the memory usage climbing without any reclamation being done even after closing all the editors and waiting several minutes. Workaround: Try to reload the vscode window when you notice memory pressure on your system. This is really annoying but I guess it's better than running out of memory :D. |
I have also been experiencing this problem, however I am not exactly working with large files but simple 10MB plain log files. The memory usage doesn't drop after having several files opened and closed. @bpasero Why did you mark this issue as "out-of-scope". This is clearly an issue, except memory leaks are considering okay by the vscode team. I'd also point out that this didn't happen with earlier releases of vscode. |
This could be electronjs issue and not solely vscode and that could be why it's out of scope for vscode. A quick test could be to create a quick json viewer using electronjs and see if the memory leak still occurs. |
I’d like to point out, that since last time I’ve tested it (some months ago), it seemed like a regression because both leaking and non-leaking release of vscode were using the same electron version. However, I am sorry I haven’t taken notes and can’t really remember, nor do I have the resources and time to bisect this “regression”. The least I can say is that I can still reliably reproduce this memory leak. |
I think it's quite irresponsible to mark this out-of-scope, this affects all of your users on all platforms. |
I believe I ran into this about a year ago (#76498) |
Guys, They have made their choice. |
There is "Improve performance, scalability, and security of VS Code and its extensions" in the roadmap. I don't see how this issue isn't relevant for that. |
Front page of HN = should probably fix hint hint ;) |
That's not how open source software works, @sam0x17. |
vscode is being used by many online IDE services like gitpod. Such memory issues could impact their performance. |
How does the memory footprint changes if you open a few files, close all of them and then open them again? Are you getting increasing memory usage until your system is out of memory, or the second time you open the same files, the memory usage doesn't increase with the same amount as it did when you opened the file for the first time? |
Allocating and freeing memory on demand without restrains will lead to memory fragmentation, degrading performance. Need 100MB? Allocate it. VSCode maintainers were totally right to descope this “bug”. If you desperately want that memory back, I’d recommend checking with Node/V8 devs for JS APIs to control memory management and/or garbage collection. |
Didn't test this myself but holding memory is not necessary a "memory leak". When we talk about memory allocations like A better memory leak would be opening and closing the same file. If you see the memory starts jumping after a couple of tries there is a memory if not it reusing the freed space. Edit: |
Maybe nudge the VSCode team to embed a CLR in VSCode as an alternative to JavaScript. |
I can get this to happen with files in the current workspace and outside of the current workspace. Opening the same file, closing it, and opening it again will cause an increase in memory usage proportional to the size of the file. The memory does not get reclaimed. This continues unbounded for me. I can get the memory to be reclaimed by opening a new workspace. I'd argue that it makes it a memory leak, since I'm testing with the same file within a single workspace, then swapping to a new workspace and immediately getting reclamation of space. Maybe that's expected behavior, but it's a bad user experience anyway if I have to keep all of my files opened all the time to avoid leaks. So far, I've only found switching workspaces to reset memory usage without restart. Reloading the current workspace does not work. Environment: |
Opening a new or restarting a workspace just circumvents the issue because it spawns a new electron renderer process which includes a new v8 instance. I have seen this top comment on Reddit:
I have also tried different files with different and I can still confirm not seeing memory being reclaimed, which means that memory buffers aren’t reused. However that does not mean that the file hasn’t been cached. That spawns another question whether v8 or vscode is caching file contents. Perhaps I’d like to mention this once again, this didn’t happen before with the same electron version iirc and different vscode releases. So the question is, did vscode introduce some sort of file caching? But that wouldn’t explain the behavior I am seeing above. Edit: I’ve tried to use the integrated profiler to take a heap snapshot, however it doesn’t seem to capture any of the memory related to the text buffer. Even with an opened ~300MB file, devtools reports a total heap size of ~60MB. |
Just wanted to add a note here for clarity: I have investigated this back in October, but I did not find a logical leak in our code. We took two heap snapshots, one taken before opening a very large file and the other one taken after closing the file. The logical JS memory usage did not grow (according to the Heap Snapshots). That is why I linked to https://chromium.googlesource.com/chromium/src.git/+/master/docs/memory/key_concepts.md , since it appeared to me that we free the memory from JS, but v8/chromium does not release the memory back to the OS. AFAIK that is typical behavior for many garbage-collected runtimes. So we simply stopped our investigation since this behavior does not come from our code-base and the behavior was different across Electron versions (with the same vscode code). |
Actually, just for completeness sake, I have tried one more time to reproduce and this time found a logical leak. The thing is that the leak only reproduces out of Insiders or Stable and not when running from source. This is due to the difference in But the following does show a clear leak: There is a listener whenever a text buffer is created that is not disposed around here -- https://github.com/microsoft/vscode/blame/c4b7d109123ca612cbe3d40e9c67575a145ec020/src/vs/workbench/contrib/extensions/browser/fileBasedRecommendations.ts#L152-L155 . @sandy081 we should remove that listener as soon as a text buffer is disposed, and I plan to also "null" out some text buffer members on my side to avoid that forgetting to dispose a listener would cause such a leak in the future. I am sorry for not noticing the logical leak back in October and thank you for bringing this issue back to my attention, such that I tried reproing again! ❤️ |
@alexdima I really appreciate that you did take a look again. Great find! ❤️
I just realized that the text buffer is stored as JSArrayBufferData, which would explain why it isn’t accounted in the total heap size. Am I right? |
@cynecx It is interesting, I don't think this is related to our usage of But something is indeed off with the Heap Snapshot because the strings stored by the text buffer do appear in the heap snapshot, but they are counted with a very small size (28 bytes). I've also seen they are of type "ExternalOneByteString". These strings are being created from Buffers via a |
First of all, sorry for causing this bug and added the fix. Here are the details about the bug and fix: We have file based recommendations ( Fixed it by disposing the model listeners the BeforeAfterBefore: There is an increase in memory (~2.6MB) every time I open a large file and close it. |
This bug has been fixed in to the latest release of VS Code Insiders! @cynecx, you can help us out by confirming things are working as expected in the latest Insiders release. If things look good, please leave a comment with the text Happy Coding! |
thanks,I'll use webstorm instead |
/verified |
I had the same problem, and the memory explosion was high |
Version: 1.50.0-insider
Commit: 0ecb64a
Date: 2020-10-02T13:37:26.948Z
Electron: 9.2.1
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Linux x64 5.8.13-arch1-1
Steps to Reproduce:
evenlarger.json
in vscode.Even after ~30 minutes, the memory usage is still high:
Does this issue occur when all extensions are disabled?: Yes
Note: This seems like a regression because I didn't had this issue before, however I don't know which insiders/stable release caused this.
The text was updated successfully, but these errors were encountered: