title: Git gc using excessive memory, unable to complete
body: <p><em><strong>Final update and fix</strong>: The solution here turned out to be a combination of two things: using Windows Git rather than Cygwin Git as <a href="https://stackoverflow.com/users/385478">Graham Borland</a> <a href="https://stackoverflow.com/a/8215746/220155">suggested</a>, and the Git config settings <code>pack.threads = 1</code> and <code>gc.aggressiveWindow = 150</code>.</em></p>
  
  <p>I have a large local Git repository, a <code>git svn clone</code> of an SVN repository with about 40,000 commits. I'm trying to run <code>git gc</code> over this repository, and getting nowhere:</p>
  
  <pre><code>$ git gc --auto
  Auto packing the repository for optimum performance. You may also
  run "git gc" manually. See "git help gc" for more information.
  Counting objects: 25966, done.
  Compressing objects: 100% (25249/25249), done.
  fatal: Out of memory, malloc failed (tried to allocate 426523986 bytes)
  error: failed to run repack
  </code></pre>
  
  <p>I'm running Git 1.7.5.1 inside Cygwin on a 64-bit dual-core Win7 machine with 4GB RAM. The <code>.git</code> directory is currently a little over 6.1GB.</p>
  
  <p>I've tried running <code>git gc --aggressive</code>, to see if the more complete system is able to fix it, but no luck: I get a similar message to the above, with the same size attempted <code>malloc</code>, but a considerably higher object count (508,485 counted, 493,506 compressed).</p>
  
  <p>I've also tried—as suggested by Google—assorted twiddles to the <code>[pack]</code> part of my <code>.gitconfig</code> file; the most complete being from <a href="https://stackoverflow.com/questions/3095737" title="Is there a way to limit the amount of memory that &quot;git gc&quot; uses?">another StackOverflow question</a>. My <code>.gitconfig</code> now has the following relevant lines, but setting these appears to have made no difference:</p>
  
  <pre><code>[pack]
          windowMemory = 16m
          threads = 1
          window = 1
          depth = 1
          deltaCacheSize = 1
  </code></pre>
  
  <p>Any suggestions on how I can get <code>git</code> to <code>gc</code> my repository?</p>
  
  <p><strong>Edit</strong>: <a href="https://stackoverflow.com/users/223092">Mark Longair</a> <a href="https://stackoverflow.com/a/8214778/220155">suggested</a> some more <code>.gitconfig</code> file changes. Which I made, new lines below. But the changes made no difference whatsoever.</p>
  
  <pre><code>[core]
          packedGitWindowSize = 1m
          packedGitLimit = 256m
  [pack]
          packSizeLimit = 128m
  </code></pre>
  
  <p><strong>Edit 2</strong>: <a href="https://stackoverflow.com/users/95382">Michael Krelin</a> <a href="https://stackoverflow.com/a/8214444/220155">suggested</a> increasing the swap/page file size (WinXP instructions <a href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sysdm_advancd_perform_change_vmpagefile.mspx?mfr=true" rel="nofollow noreferrer" title="To change the size of the virtual memory paging file">here</a>, and it's similar for Win7). I tried that, but it made no difference, and indeed I only increased the maximum size available, and it looks as if Windows never tried to increase the size of the page file it was using.</p>
  
  <p>I'm now looking at whether this was caused by a memory limit within or imposed upon Cygwin. To check "imposed upon", I'm trying running Cygwin with administrator privileges. To check "within" (which looks more likely), I'm having a play with <a href="http://cygwin.com/cygwin-ug-net/setup-maxmem.html" rel="nofollow noreferrer" title="Changing Cygwin&#39;s maximum memory">Cygwin's maximum memory settings</a>.</p>
  
  <p><strong>Edit 3</strong>: Much though I may prefer using Cygwin, it turns out the Windows Git client deals with the memory issue just fine. Seems I'll be falling back to that every so often when my repository needs a tidy.</p>