-
Notifications
You must be signed in to change notification settings - Fork 0
Auto Free GC
Hugo edited this page Feb 26, 2026
·
1 revision
CoreTrace auto-free has two layers:
- compile-time feature enable (
--ct-autofree) - optional conservative runtime scanning (
CT_AUTOFREE_SCAN*)
Auto-free is disabled by default in compile-time runtime config. Enable it when building instrumented binaries:
./build/cc --instrument --ct-alloc --ct-autofree main.c -o appWithout scan variables, auto-free only uses compile-time reachability decisions. To enable conservative root scanning:
CT_AUTOFREE_SCAN=1 ./appTo enable periodic GC thread:
CT_AUTOFREE_SCAN=1 CT_AUTOFREE_SCAN_START=1 ./app| Variable | Default | Meaning |
|---|---|---|
CT_AUTOFREE_SCAN |
0 |
Enable conservative scan system |
CT_AUTOFREE_SCAN_START |
0 |
Start background periodic scan thread |
CT_AUTOFREE_SCAN_STACK |
1 |
Scan stack roots |
CT_AUTOFREE_SCAN_REGS |
1 |
Scan register roots |
CT_AUTOFREE_SCAN_GLOBALS |
1 |
Scan globals (__DATA/image data) |
CT_AUTOFREE_SCAN_INTERIOR |
1 |
Count interior pointers as roots |
CT_AUTOFREE_SCAN_PTR |
1 |
Run per-pointer check before auto-free |
CT_DEBUG_AUTOFREE_SCAN |
0 |
Debug level (0/1/2) |
Period precedence:
CT_AUTOFREE_SCAN_PERIOD_NSCT_AUTOFREE_SCAN_PERIOD_USCT_AUTOFREE_SCAN_PERIOD_MS- fallback
1000mswhenSTART=1and no period is set
Budget precedence:
CT_AUTOFREE_SCAN_BUDGET_NSCT_AUTOFREE_SCAN_BUDGET_US-
CT_AUTOFREE_SCAN_BUDGET_MS(default5.0)
Compatibility interval:
-
CT_AUTOFREE_SCAN_INTERVAL_MSsets a minimum interval for per-pointer scans.
CT_AUTOFREE_SCAN=1 \
CT_AUTOFREE_SCAN_START=1 \
CT_AUTOFREE_SCAN_PTR=1 \
CT_AUTOFREE_SCAN_GLOBALS=1 \
CT_AUTOFREE_SCAN_PERIOD_MS=1000 \
CT_AUTOFREE_SCAN_BUDGET_MS=20 \
./appCT_AUTOFREE_SCAN=1 \
CT_AUTOFREE_SCAN_START=1 \
CT_AUTOFREE_SCAN_GLOBALS=0 \
CT_AUTOFREE_SCAN_PTR=0 \
CT_AUTOFREE_SCAN_PERIOD_MS=5000 \
CT_AUTOFREE_SCAN_BUDGET_MS=5 \
./app- Conservative roots can keep dead allocations alive (false negatives).
- If budget is exceeded, scan avoids freeing in that pass for safety.
- Pointer scanning and global scanning can be expensive on large processes.
Start
Architecture
Instrumentation
Developer