Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get Visual Studio To Stay Within 4GB Virtual Address Space

The Visual Studio devenv.exe process is 32-bit (even when run on a 64-bit OS), so it can't use more than 4GB of virtual memory.

Unfortunately, when I am debugging my C++ application with Visual Studio I frequently run out of memory due to this 4GB limit. For example, using VMMap, below shows progression of my typical Visual Studio usage over a few hours leading to a crash.

How can I get Visual Studio to use less memory so I stop wasting time with it crashing?

Is it typical for Visual Studio to use more than 3.5 GB virtual address space?

I am using Visual Studio 2012, but I assume this problem spans different VS versions, since Visual Studio 2015 still doesn't have a 64-bit version.

(Note that VMMap reports “Free” as the remaining memory in the address space, up to 4GB for 32 bit processes, and 8TB for 64 bit processes on Windows.)

enter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description hereenter image description here


Things I've already tried:

  • starting in safe mode
  • removing all plugins and extensions so that nothing shows in Tools > Add-in Manager nor Tools > Extensions (https://github.com/tsasioglu/Total-Uninstaller is helpful for this)
  • deleting my .suo/.sdf files
  • deleting my AppData/*/Microsoft/VisualStudio folders
  • using Funnel and filtering out all but 3 projects
  • removed all my "Symbol file (.pdb) locations" selections and chose "Automatically load symbols for: " "Only specified modules"
  • selected "Enable Just My Code" for debugging
  • disabling Intellisense (Tools -> Options -> Text Editor -> C/C++ -> Advanced -> Disable IntelliSense)
like image 758
JDiMatteo Avatar asked Jul 01 '15 19:07

JDiMatteo


People also ask

How do I add more memory to Visual Studio?

Use a 64-bit OS If you upgrade your system from a 32-bit version of Windows to a 64-bit version, you expand the amount of virtual memory available to Visual Studio from 2 GB to 4 GB. This enables Visual Studio to handle significantly larger workloads, even though it is 32-bit process.

Can you run out of virtual memory addresses?

If your specific process attempts to exceed the size of process virtual address space, it will simply run out of memory. What will happen is exactly what normally happens when your process runs out of memory - memory allocation function will return null pointer or something like that.

Is virtual address space the same as virtual memory?

Virtual memory is a memory management technique developed for multitasking kernels. Virtual address space is a memory mapping mechanism available in modern operating systems. So the answer is: yes, these are quite different terms.

What is the size of virtual address space in 64-bit systems?

In 64-bit Windows, the theoretical amount of virtual address space is 2^64 bytes (16 exabytes), but only a small portion of the 16-exabyte range is actually used.


1 Answers

It is possible to reliably get Visual Studio to stay within it's 4GB of virtual memory, but you might have to experiment with one or more of the following strategies while measuring devenv.exe memory usage with VMMap:

  1. remove plugins and extensions from Tools > Add-in Manager and Tools > Extensions (https://github.com/tsasioglu/Total-Uninstaller might be helpful) and/or run in Safe Mode
  2. periodically (e.g. monthly) delete your .sdf and .suo files (while Visual Studio is closed) so they can be recreated (instead of deleting, consider just renaming in case you decide you want them back, as you may loose some configuration settings)
  3. If you are loading a lot of symbols (you can count "Symbols loaded" in the VS Output window), you can disable this with Tools > Options > Debugging > Symbols: "Only specified modules", then click "Specify modules" and uncheck "Always load symbols located next to modules". You can load additional symbols while debugging with Debug > Windows > Modules.
  4. Unload projects from large solutions with Funnel or Solution Folders
  5. If all else fails, run two different Visual Studio instances: the first has the large solution loaded but is not used to debug (e.g. Debug > Start without Debugging), and the second has no solution loaded but is attached to the running process for debugging. (Thanks ChrisO for this suggestion.)
  6. If you really can't get Visual Studio to work, try WinDbg which is used by Microsoft developers and is 64-bit (unlike Visual Studio).

I have observed disabling most symbol loading reducing devenv memory usage by 1.7 GB and deleting my .suo and .sdf file reducing memory usage by an additional 600 MB. This reduction in memory usage made Visual Studio go from crashing multiple times a day to running stable with the same instance running for multiple days, sometimes weeks.

In addition to reducing memory usage, these strategies will likely significantly speed up Visual Studio.

like image 104
JDiMatteo Avatar answered Oct 16 '22 04:10

JDiMatteo