Finding a VS Code Memory Leak

randomascii.wordpress.com

93 points by brucedawson 4 days ago


brucedawson - 4 days ago

In 2021 I found an invisible memory leak in a tool (VS Code) that I have never used. This is the story of how.

delta_p_delta_x - 3 days ago

Great analysis, but the solution is so simple: RAII.

And this is offered as `unique_process_handle`[1] in the Windows Implementation Library (WIL)[2].

This is a fantastic addition to the Windows developer's toolkit, which everyone should be using from the outset. The Windows C API is unnecessarily verbose (although this can be said of any OS, Windows' is particularly bad), and simple mistakes can and will happen.

Let RAII help you, let the mighty close-scope token `} ` be your best friend.

[1]: https://github.com/microsoft/wil/blob/1f20cd086e07b9be54e70d...

[2]: https://github.com/microsoft/wil

criemen - 4 days ago

> For obscure technical reasons they are always multiples of four.

Why did I know that that link went to Raymond Chen before clicking it... That man is a treasure.

anonymars - 4 days ago

> Sometimes I think it would be nice to have limits on resources in order to more automatically find mistakes like this

I was actually fairly disappointed when Visual Studio (not code) went to 64-bit. Because I knew its memory usage was now going to be unconstrained. Still way better than the unapologetic gluttony of Rider but experiences showed it to be a bit leaky over time (tip: Ctrl-Alt-Shift-F12 twice does a full garbage collection https://learn.microsoft.com/en-us/visualstudio/ide/visual-st...)

Also remember that all your references (pointers) are going to double in size so right off the bat it will use more, potentially a lot more depending on how reference-heavy your data is

aborsy - 3 days ago

The code base for VSCode seems to be huge. With plug-ins, bloat, all the different things that it does, and large number of installations, it seems an ideal target for vulnerabilities and supply chain attacks.

Anyone knows more the level of risk?

userbinator - 3 days ago

In this case I noticed that the process IDs on her system had seven digits.

I believe on Windows 9x, process IDs are actual kernel addresses (pointers to the process structure), and thus always have 10 digits.

anonymousDan - 4 days ago

Re the last wish, isn't that exactly what ulimit is for?

seivan - 4 days ago

[dead]