Why do I get a System.OutOfMemoryException error when building from source?

I am trying to build the 4.0.1 build from github with MSVS Express 2013 running on windows 7.
When i try to build i get these errors after about 15 seconds

Error	1	error : System.OutOfMemoryException: Insufficient memory to continue the execution of the program.	E:\UE4\UnrealEngine\Engine\Intermediate\ProjectFiles\EXEC	UE4
Error	2	error : UnrealHeaderTool failed for target 'UE4Editor' (platform: Win64, module info: E:\UE4\UnrealEngine\Engine\Intermediate\Build\Win64\UE4Editor\Development\UnrealHeaderTool.manifest).	E:\UE4\UnrealEngine\Engine\Intermediate\ProjectFiles\EXEC	UE4
Error	3	error MSB3073: The command "..\..\Build\BatchFiles\Build.bat UE4Editor Win64 Development" exited with code -1.	C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets	38	5	UE4

VS Output

    1>------ Build started: Project: UE4, Configuration: Development_Editor x64 ------
    1>  Building UnrealHeaderTool...
    1>EXEC : error : System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
    1>     at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
    1>     at System.Management.ManagementScope.InitializeGuts(Object o)
    1>     at System.Management.ManagementScope.Initialize()
    1>     at System.Management.ManagementObjectSearcher.Initialize()
    1>     at System.Management.ManagementObjectSearcher.Get()
    1>     at UnrealBuildTool.LocalExecutor.ExecuteActions(List`1 Actions) in e:\UE4\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\System\LocalExecutor.cs:line 289
    1>     at UnrealBuildTool.UnrealBuildTool.ExecuteActions(List`1 ActionsToExecute, String& ExecutorName) in e:\UE4\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\System\ActionGraph.cs:line 267
    1>     at UnrealBuildTool.UnrealBuildTool.RunUBT(String[] Arguments) in e:\UE4\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\System\UnrealBuildTool.cs:line 1109
    1>  Cumulative action seconds (8 processors): 0.00 building projects, 0.00 compiling, 0.00 creating app bundles, 0.00 generating debug info, 0.00 linking, 0.00 other
    1>  UBT execution time: 6.18 seconds
    1>EXEC : error : UnrealHeaderTool failed for target 'UE4Editor' (platform: Win64, module info: E:\UE4\UnrealEngine\Engine\Intermediate\Build\Win64\UE4Editor\Development\UnrealHeaderTool.manifest).
    1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command "..\..\Build\BatchFiles\Build.bat UE4Editor Win64 Development" exited with code -1.
    ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

As for Error 3 i tried running ‘Engine\Build\BatchFiles\Build.bat’ buy hand it comes up
UnrealBuildTool Exception: Error: Couldn’t find platform name.

Hey Mrtn,

Could you provide us with your dxdiag readout?

Thanks,

-Steve

Hi Mrtn,

This might be a red-herring however, it appears you are out of memory:

System.OutOfMemoryException: Insufficient memory to continue the execution of the program.

Any chance you are out of harddrive space on your C drive? How much RAM do you have?


System Information
------------------
Time of this report: 3/21/2014, 22:45:58
Machine name: MRGH-PC
Operating System: Windows 7 Professional 64-bit (6.1, Build 7601) Service Pack 1 (7601.win7sp1_gdr.130828-1532)
Language: English (Regional Setting: English)
System Manufacturer: System manufacturer
System Model: System Product Name
BIOS: BIOS Date: 08/19/13 10:33:12 Ver: 19.03
Processor: Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz (8 CPUs), ~3.5GHz
Memory: 16384MB RAM
Available OS Memory: 16326MB RAM
Page File: 4435MB used, 28216MB available
Windows Dir: C:\Windows
DirectX Version: DirectX 11
DX Setup Parameters: Not found
User DPI Setting: Using System DPI
System DPI Setting: 96 DPI (100 percent)
DWM DPI Scaling: Disabled
DxDiag Version: 6.01.7601.17514 32bit Unicode

------------------------
Disk & DVD/CD-ROM Drives
------------------------
Drive: C:
Free Space: 157.6 GB
Total Space: 228.8 GB
File System: NTFS
Model: Corsair Force GS

Drive: E:
Free Space: 261.3 GB
Total Space: 476.9 GB
File System: NTFS
Model: WDC WD5002AALX-00J37A0

(Did you need the hole file ?)

I have 228-Gb and 261-Gb free on the HD’s, and i have 16-Gb memory.

@Mrtn

I recommend viewing this page (visual studio 2010 exception of type system.outofmemoryexception' was thrown) to determine if any of the recommended solutions may apply to you.

Cheers

Hey Mrtn,

If you can save out the file and attach it for us, that would be great.

-Steve

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

I ran into this problem too and it turns out that Comodo, the anti-malware I’m using, had been sandboxing various programs that were trying to run while compiling. Simply trusting those unrecognized files made all the difference. (Please make good judgement when trusting files.) VS Express 2013 for Desktop is blissfully compiling with only 6 GB of RAM.