1

I have a very large C# file (auto generated from grammer - >100K lines). When I try to create a solution and include this file - after about 10 seconds, VS crashes due to out of memory. I see that it happens when its memory consumption reaches ~2GB. Is there any way to configure VS to use more memory? I am running this on a machine with 32GB, so I have plenty of memory to use. Or, is there any other solution to this problem?

duduamar
  • 3,816
  • 7
  • 35
  • 54
  • This is a silly question. If it's code generated, what do you even have to open it? If you think you have to manage it manually, then you must refactor the code. I would open the file in notepad++ and break it down. Also, if you have resharper, make sure it's disabled, or this file is excluded. – Kosala W Feb 03 '16 at 06:41
  • What version of Visual Studio? Do you have any plagins like was mentioned in [this question](http://stackoverflow.com/questions/207902/how-best-to-deal-with-gigantic-source-code-files-in-visual-studio)? – Michael Feb 03 '16 at 06:42
  • This file is generated with errors - so I am trying to debug why. @VMA - this is VS2015, I have resharper but it still happens after disabling it. I guess my main question is why VS doesn't use more than 2GB ? – duduamar Feb 03 '16 at 06:42
  • It's the number of lines that it has to debug. VS always had this kind of issues with large files. Not just VS, any IDE will struggle with 100k LOC. – Kosala W Feb 03 '16 at 06:47
  • 1
    "Why VS doesn't use more than 2GB"? - Because it's still [a 32bit Application](https://answers.microsoft.com/en-us/windows/forum/windows_7-performance/32-bit-program-has-2gb-limit-on-64-bit-os/1ba667f7-d983-48c2-bc9e-e2e9c394bb79) – Random Dev Feb 03 '16 at 06:51
  • Thanks @Carsten, that's news to me... I guess that says nothing much i can do about it. – duduamar Feb 03 '16 at 06:53
  • that close vote is simply incorrect. Its a question about a code-editor failing due to the size of the code. Its a problem can can go away if you change the code. Ergo its a code related. – Meirion Hughes Feb 05 '16 at 12:49

2 Answers2

2

If you have more than one class then separate out all the classes into their own files when you do the generation.

If you have one massive class then separate out method into separate files using the partial keyword.

Unless you have one class, with one method, that does something different to every element of an extremely large data-set, there is no reason why should not employ Single Responsibility Principle and break it all up into small, reusable classes - even if its generated.

Community
  • 1
  • 1
Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122
1

As KosalaW suggested, open it in an external program such as Notepad++ or Textpad (I'd suggest the latter, as I've had issues with large files in Notepad++).

If you must have it as is, assuming you're generating this 100k line file, I'd recommend dumping it into multiple, smaller files. If you're wanting to read it in programatically, you can read in each smaller file one at a time and run through it line by line, or even rejoin them and analyse them programatically.

Corey Thompson
  • 398
  • 6
  • 18