9

When playing with various algorithms in Haskell it often happens to me that I create a program with a memory leak, as it often happens with lazy evaluation. The program taking all the memory isn't really fun, I often have difficulty killing it if I realize it too late.

When using GHC6 I simply had export GHCRTS='-M384m' in my .bashrc. But in GHC7 they added a security measure that unless a program is compiled with -rtsopts, it simply fails when it is given any RTS option either on a command line argument or in GHCRTS. Unfortunately, almost no Haskell programs are compiled with this flag, so setting this variable makes everything to fail (as I discovered in After upgrading to GHC7, all programs suddenly fail saying "Most RTS options are disabled. Link with -rtsopts to enable them.").

Any ideas how to make any use of GHCRTS with GHC7, or another convenient way how to prevent my programs taking all memory?

4
  • 3
    There are of course solutions independent of Haskell, just limiting the memory usage of particular processes. Is this a Linux? — But why don't you just use -rtsopts for a program you know to be memory-critical? Commented Sep 7, 2012 at 18:44
  • 1
    @leftaroundabout What he's saying is that he likes to turn on the -M384M option by default for his own programs using the GHCRTS environment variable, but now he can't do it because other Haskell tools (such as, perhaps, cabal-dev) will fail when given an RTS parameter. Commented Sep 7, 2012 at 19:09
  • 4
    On Linux you can use ulimit -m to limit the amount of memory processes started from a shell can take. Other *nixes probably have some variation on the ulimit switches they accept.
    – ninjalj
    Commented Sep 7, 2012 at 19:32
  • @ninjalj: sure -m does the trick? I always use -v. But I don't really understand that *nix slang or what it is, "maximum resident set size"... Commented Sep 7, 2012 at 20:18

1 Answer 1

5

You can compile your own programs with -with-rtsopts=-M384m to set RTS options at compile time (once and for all). You could also set up a "blacklist" of programs that shouldn't be run with GHCRTS in your .bashrc; perhaps something like

for i in foo bar baz
do
    alias $i="GHCRTS= $i"
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.