rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.12k stars 1.58k forks source link

Memory Leak on MacOS. Using +7gb Memory on Empty Project #16140

Open kyle-tennison opened 9 months ago

kyle-tennison commented 9 months ago
image image

When I open the parent dir of any rust project, it looks like there is some sort of memory leak; the "rust-analyzer" icon spins indefinitely as memory racks up. I'm on macOS Ventura 13.1 on M1 (macbook air 2020). I have no issues whatsoever when I open the crate's directory directly.

I really like this plugin, so I hope this helps. Good luck!

rust-analyzer version: v0.4.1773 (plus whatever the main release is)

rustc version: rustc 1.73.0 (cc66ad468 2023-10-03)

relevant settings: Everything vanilla. No env vars set.

kyle-tennison commented 9 months ago

The steps to recreate

  1. mkdir parent_dir
  2. cd parent_dir
  3. mkdir project_dir
  4. cd project_dir
  5. cargo init
  6. code .. (open vscode in parent dir)
  7. open main.rs in vscode
  8. wait a minute for memory to rack up
lnicola commented 9 months ago

Can't reproduce on Linux.

Veykril commented 6 months ago

Can't repro this on windows either

DrewMcArthur commented 6 months ago

@Veykril is this something that got fixed or just was not reproducible? i'm getting around 40gb of memory usage on macOS, with an M2 mbp. 16gb of actual ram, so it's filling up all my swap too. this has been happening pretty consistently working on a specific project, most recently when i changed git branches. I had also changed to the prerelease version, and had the same issue. happy to help try to find the source of this.

Screenshot 2024-03-24 at 12 15 30 PM Screenshot 2024-03-24 at 12 15 58 PM Screenshot 2024-03-24 at 12 16 05 PM Screenshot 2024-03-24 at 12 15 53 PM

Sample of rust-analyzer.txt

edit; i think it has to do with the format-on-save functionality. i save a file, and sometimes it hangs, i get a notification in vs code that it's trying to run the formatter before saving. i have to cancel that to save the file, and then the memory usage quickly balloons. here's a screenshot.

Screenshot 2024-03-24 at 1 24 37 PM
Veykril commented 6 months ago

Not reproducible, if you have a leak problem please update to the latest release and check again

kyle-tennison commented 6 months ago

@Veykril , the example I provided may indeed be reproducible—just not on other OS's. The issue is still present on the latest release, and considering somebody else has bumped into the same issue on MacOS, it might be a mac-specific bug. I appreciate your help though.

@DrewMcArthur , if you're open to it, it would be awesome if you could let us know if the example in the original post will cause a leak for you too; this way, we can verify the issue is reproducible on other mac machines.

Veykril commented 6 months ago

Then someone with a mac will have to investigate as I don't have such a machine.

DrewMcArthur commented 6 months ago

i think #16935 fixed my issue but i'll see if i can reproduce

Hugo4IT commented 2 months ago

Hello, I have this problem too, my M1 mac has crashed multiple times due to rust-analyzer using up more than 30 gigs of ram and it running out. I am now required to keep task manager open while I use it so that I can kill rust-analyzer when it lags for a while before it crashes my whole system again. I only have this on my macbook, on linux and windows I have not had this issue. I don't want to put any pressure here, it is manageable, but I would love to help diagnose the issue in any way I could. Is there anything I can provide to help? One thing I can say is that I love doing insane stuff with macros and usually the worse my macros get the worse the problem gets, so maybe it has something to do with that?

Veykril commented 2 months ago

Can you run the command: rust-analyzer: Memory Usage (Clear Database) the next time you observe a very high memory usage? That will give us some rough stats