When trying to debug memory usage, is there a config that I can pass to my crystal executable that would limit the size of its heap, so that it doesn’t grow indefinitely?
That’s particularly useful when debugging memory leaks and you want to cause an out-of-memory error sooner rather than later.
In Java you can do -Xmx4g
Crystal uses the boehm GC, so anything you can configure there you can configure here too:
The garbage collector looks at a number of environment variables which are,
then, used to affect its operation.
GC_INITIAL_HEAP_SIZE=<bytes> - Initial heap size in bytes. May speed up
process start-up. Optionally, may be
specified with a multiplier ('k', 'M' or 'G')
suffix.
GC_MAXIMUM_HEAP_SIZE=<bytes> - Maximum collected heap size. Allows
a multiplier suffix.
GC_LOOP_ON_ABORT - Causes the collector abort routine to enter a tight loop.
This may make it easier to debug, such a process, especially
for multi-threaded platforms that don't produce usable core
files, or if a core file would be too large. On some
platforms, this also causes SIGSEGV to be caught and
result in an infinite loop in a handler, allowing
similar debugging techniques.
GC_PRINT_STATS - Turn on GC logging. Not functional with SMALL_CONFIG.
This file has been truncated. show original
It seems you can pass an GC_MAXIMUM_HEAP_SIZE
environment variable to the executable:
3 Likes