Computer grinds to a halt and crashes due to lack of memory after doing "Cleanup All Code in Solution" on big solution
Environment
- Visual Studio version: 2019 Enterprise v16.8.5
- CodeMaid version: 11.2
- Code language: C#
Description
Unfortunately, due to the fact that the computer crashed, I do not have logs.
I have a solution. It has approx 250 projects in it. When I click the Code Maild menu command "Cleanup All Code in Solution," it informs me that there are 1306 files in the solution, and do I confirm I want to clean them all? I say yes.
After about File 536 of 1306, In the Output window, there is the dialog that says an unhandled .NET exception has occurred in devenv.exe do you want to debug (JIT debugger)? I click No, and VS crashes. There are messages in the Output window showing CodeMaid experiencing unhandled exceptions and not having enough memory. The computer works extremely slowly after the operation fails. It takes 30 seconds just to type a single letter into a text box, for example.
Steps to recreate
- Open a solution with 200+ projects and 1000+ source files
- Click Code Maid -> Cleanup all code in Solution menu item
- Confirm prompt by clicking Yes.
Current behavior
See above. The computer is brought to its knees by memory leaks.
Expected behavior
All 1000+ files should be processed with no crashing or memory slowdowns.
Thanks for reporting the issue. Unfortunately this is a known limitation that simply opening and closing thousands of files in Visual Studio will eventually crash the IDE due to memory leaks (with or without CodeMaid). See #209 for some more details and analysis. To be fair this is an analysis against an earlier version of Visual Studio.
The proposed workaround is to basically clean a batch of projects at a time and close/reopen Visual Studio in between. It's not ideal but it works.
Another thought is simply gather the file names of documents from whatever the user selects, and then use C# File.ReadAllText and WriteAllText totally independently of VS, to do the sorting and organizing using string parsing and tokenizing operations.
-Brian
On 03/03/2021 9:05 AM Steve Cadwallader <[email protected]> wrote:
Thanks for reporting the issue. Unfortunately this is a known limitation that simply opening and closing thousands of files in Visual Studio will eventually crash the IDE due to memory leaks (with or without CodeMaid). See #209 for some more details and analysis. To be fair this is an analysis against an earlier version of Visual Studio. The proposed workaround is to basically clean a batch of projects at a time and close/reopen Visual Studio in between. It's not ideal but it works. —You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.
Thanks for the suggestion. While some of the code cleanups are raw text and can be easily applied without the IDE (e.g. remove end of line whitespace) there are other edits that require the semantic awareness of the IDE (e.g. if this is a method declaration, but it is not a part of an explicit interface implementation and it does not currently have an access modifier, please inject the access modifier in the correct location).
Touche.
Well, just wanted to check.
-Brian
On 03/17/2021 8:11 AM Steve Cadwallader ***@***.***> wrote:
Thanks for the suggestion. While some of the code cleanups are raw text and can be easily applied without the IDE (e.g. remove end of line whitespace) there are other edits that require the semantic awareness of the IDE (e.g. if this is a method declaration, but it is not a part of an explicit interface implementation and it does not currently have an access modifier, please inject the access modifier in the correct location). —You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.
Just had the issue recur again. I did a Cleanup All Code in Solution, and out of 1533 total files, only 276 got addressed before an unhandled exception occurred in devenv.exe (I got the JIT debugging box). I clicked Cancel, and then VS crashed.
As a workaround, could CodeMaid do the following (pseudocode):
if (number_of_files > 250)
break files up into groups of 250 apiece
foreach group in groups
process group
sleep for, e.g, 1-5 seconds
end foreach loop
end if
Just a thought. Also, to interact with VS DTE, you are using IOleMessageFilter as suggested in the following post:
https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/ms228772(v=vs.100)?redirectedfrom=MSDN
That would not, in principle, address the issue if it is due to a memory leak within the Visual Studio product itself, however. But I am just throwing this out.
--> If you like I can try to get more diagnostic information by clicking the button to invoke the JIT debugger and see what it tells me.
IIRC the memory growth did not get reclaimed even if you paused. If you clean a large batch (e.g. 100-250) and then pause do you see the memory size return to normal?
We are not using IOleMessageFilter but that article appears to be referencing VS add-ins (vs. extensions) which have been deprecated.