{"record":{"id":"123096d03cf7da40","repo":"dotnet/runtime","slug":"max-heap-size-must-be-an-integer-n","errorCode":null,"errorMessage":"max-heap-size must be an integer.\\n","messagePattern":"max-heap-size must be an integer\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/mono/mono/metadata/boehm-gc.c","lineNumber":176,"sourceCode":"\tGC_init_gcj_malloc (5, NULL);\n\tGC_allow_register_threads ();\n\n\tif ((env = g_getenv (\"MONO_GC_PARAMS\"))) {\n\t\tchar **ptr, **opts = g_strsplit (env, \",\", -1);\n\t\tfor (ptr = opts; *ptr; ++ptr) {\n\t\t\tchar *opt = *ptr;\n\t\t\tif (g_str_has_prefix (opt, \"max-heap-size=\")) {\n\t\t\t\tsize_t max_heap;\n\n\t\t\t\topt = strchr (opt, '=') + 1;\n\t\t\t\tif (*opt && mono_gc_parse_environment_string_extract_number (opt, &max_heap)) {\n\t\t\t\t\tif (max_heap < MIN_BOEHM_MAX_HEAP_SIZE) {\n\t\t\t\t\t\tfprintf (stderr, \"max-heap-size must be at least %dMb.\\n\", MIN_BOEHM_MAX_HEAP_SIZE_IN_MB);\n\t\t\t\t\t\texit (1);\n\t\t\t\t\t}\n\t\t\t\t\tGC_set_max_heap_size (max_heap);\n\t\t\t\t} else {\n\t\t\t\t\tfprintf (stderr, \"max-heap-size must be an integer.\\n\");\n\t\t\t\t\texit (1);\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t} else if (g_str_has_prefix (opt, \"toggleref-test\")) {\n\t\t\t\tregister_test_toggleref_callback ();\n\t\t\t\tcontinue;\n\t\t\t} else {\n\t\t\t\t/* Could be a parameter for sgen */\n\t\t\t\t/*\n\t\t\t\tfprintf (stderr, \"MONO_GC_PARAMS must be a comma-delimited list of one or more of the following:\\n\");\n\t\t\t\tfprintf (stderr, \"  max-heap-size=N (where N is an integer, possibly with a k, m or a g suffix)\\n\");\n\t\t\t\texit (1);\n\t\t\t\t*/\n\t\t\t}\n\t\t}\n\t\tg_free (env);\n\t\tg_strfreev (opts);\n\t}","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/mono/mono/metadata/boehm-gc.c#L158-L194","documentation":"Emitted during Mono Boehm GC init in mono_gc_base_init (boehm-gc.c:176) when a `max-heap-size=` token is present but mono_gc_parse_environment_string_extract_number returns FALSE. That helper fails on an empty string, a non-digit last character that is not a valid k/m/g suffix, strtol overflow (ERANGE), or a suffix form with trailing characters after the suffix. On failure the runtime prints 'max-heap-size must be an integer.' and calls exit(1), killing the process at GC init before managed code runs.","triggerScenarios":"Boehm-GC Mono runtime started with MONO_GC_PARAMS=max-heap-size=<bad>, where <bad> is empty (max-heap-size=), non-numeric (max-heap-size=abc), contains trailing garbage (max-heap-size=64mb, max-heap-size=10x), uses an unsupported suffix (max-heap-size=64b), or overflows size_t. The parser in parse.c:28 rejects all of these and returns FALSE, tripping the else-branch fprintf at boehm-gc.c:176.","commonSituations":"Writing 'mb'/'MB' instead of 'm' (the helper only accepts a single m/M/k/K/g/G); a stray space or unit; an empty value from a templated env file; copy-pasting a Java -Xmx style value; value too large for the platform size_t (ERANGE); shell-quoting dropping the number.","solutions":["Use a plain integer or a single k/m/g suffix: MONO_GC_PARAMS=max-heap-size=256m (not 256mb / 256MB).","Remove any trailing unit characters, spaces, or quotes; the token after '=' must be digits optionally followed by exactly one of k/m/g (case-insensitive).","For very large values, drop down a suffix to avoid size_t overflow (e.g. prefer 4g over 4294967296).","Validate MONO_GC_PARAMS in a launch wrapper (parse the same way) before starting Mono so misconfigurations fail with your own message.","Inspect for accidental empty assignments from CI/CD templating (e.g. MONO_GC_PARAMS=max-heap-size=$HEAP where $HEAP is unset)."],"exampleFix":"# before\n$ MONO_GC_PARAMS=max-heap-size=256mb mono app.exe   # 'mb' is invalid\nmax-heap-size must be an integer.\n# (process exits)\n\n# after\n$ MONO_GC_PARAMS=max-heap-size=256m mono app.exe","handlingStrategy":"validation","validationCode":"# Validate max-heap-size syntax (digits + optional single k/m/g) exactly as mono_gc_parse_environment_string_extract_number does.\npython3 - <<'PY'\nimport os, re\nfor tok in os.environ.get('MONO_GC_PARAMS','').split(','):\n    m = re.match(r'^max-heap-size=(.*)$', tok.strip())\n    if not m: continue\n    val = m.group(1)\n    if not re.match(r'^\\d+[kKmMgG]?$', val):\n        raise SystemExit(f'ERROR: max-heap-size={val!r} is not <integer>[k|m|g]; use e.g. 256m')\nprint('MONO_GC_PARAMS OK')\nPY\nexec mono \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exactly one suffix letter — k, m, or g (case-insensitive). 'mb', 'MB', 'gb', 'b' are all invalid.","Never leave the value empty; guard against unset template variables (max-heap-size=$HEAP with HE unset).","For very large heaps prefer a suffix (4g) over a huge bare number to avoid size_t overflow (ERANGE).","Validate MONO_GC_PARAMS in a pre-launch wrapper so misconfigurations surface as your own error, not an exit(1) at GC init."],"tags":["mono","boehm-gc","garbage-collector","environment-variable","mono-gc-params","startup","configuration"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}