Search code examples
memoryracketlimit

Specify memory limit in Racket


In DrRacket I can set a memory limit using the GUI. However, I find the editor not sooo good and want to use another editor of my choice. But how do I specify the memory limit then?

I can think of two possibilities, but couldn't find anything about either of these:

  • at the beginning of the code call some function to set the memory limit
  • when invoking racket (not DrRacket GUI tool, but the REPL on command line) give it some arguments to specify the limit

Solution

  • At the beginning of the code, you can set a memory limit for the module. (docs)

    #lang racket/base
    (define MAX-BYTES 1000)
    (custodian-limit-memory (current-custodian) MAX-BYTES)
    
    ....
    

    I don't know a straightforward command-line solution, but you can call custodian-limit-memory in your racketrc file to set a limit for the REPL.

    See also racket/sandbox, especially call-with-limits.