[Haskell-cafe] ghc leaking memory?

Simon Marlow marlowsd at gmail.com
Mon Mar 8 06:07:30 EST 2010

On 06/03/2010 18:43, Antoine Latter wrote:
> Including ghc-users.
> On Sat, Mar 6, 2010 at 11:57 AM, Joachim Breitner<nomeata at debian.org>  wrote:
>> Hi,
>> in Debian, we are having some problems building large libraries (such as
>> agda, highlighting-kate, xmonad-contrib) on weaker architectures (sparc,
>> armel, s390) which compile with -fvia-C, especially when building the
>> profiling libraries.
>> In the case of highlighting-kate, there were really issues with the
>> code: A huge list of words which ghc seemed to try to inline caused it
>> consuming a lot of memory.
>> But in the case of agda, it even fails with relatively small modules:
>> https://buildd.debian.org/fetch.cgi?pkg=agda&arch=sparc&ver=2.2.6-3&stamp=1267334936&file=log&as=raw
>> Now, looking at the memory gauge on my computer while compiling such a
>> program with Cabal (which compiles all modules in one ghc call), it
>> looks like it is steadily increasing. I’d expect ghc to free a lot of
>> memory when it is done with a module, but this does not seem to be the
>> case.
>> Is this a bug (i.e. memory leak) in ghc or expected behavior?

Can you verify that it is GHC leaking memory, and not gcc?  I recommend 
turning off -fvia-C in particular unless you're sure that you need it.

It is expected that a --make compilation grows in memory over time, 
since the compiler accumulates information about modules that it has 
loaded.  Having said that, it should not be retaining the entire 
compiled code of each module, only its interface.  It might be hard to 
tell - in any case if you have an example where --make appears to be 
retaining too much memory then you should submit it as a bug.

>> Is there a way to make Cabal build each module on its own?

not at the moment, sorry.

 >> Are there any fixes or work-arounds?

You can try using GC settings, e.g. +RTS -M<size>.  It might be a good 
idea to set this using an environment variable, e.g. GHCRTS=-M<size> 
where <size> is roughly equal to the amount of real memory on your machine.


More information about the Glasgow-haskell-users mailing list