Memory Management
Wyn uses an arena allocator. Strings and arrays are allocated from a per-thread arena that grows as needed.
For Short-Lived Programs
No action needed. The arena is freed when the program exits.
For HTTP Servers
Http.accept() automatically resets the arena per request. Memory stays stable.
For Long-Running Programs
Call System.gc() periodically to reset the arena:
wyn
while true {
process_batch()
System.gc() // Reset arena
}defer
Use defer to run cleanup at the end of a scope:
wyn
fn process_file(path: string) -> int {
var content = File.read(path)
defer File.delete("/tmp/work.txt") // Runs when function returns
File.write("/tmp/work.txt", content.upper())
// ... do work ...
return 0
} // defer runs here--mem-stats
Check memory usage with:
bash
wyn run myapp.wyn --mem-statsShows peak resident set size after execution.
WYN_STRICT Mode
Set WYN_STRICT=1 to make the runtime exit on errors instead of continuing:
bash
WYN_STRICT=1 wyn run myapp.wynThis catches:
- Array out-of-bounds access
- Integer overflow (with
Math.checked_add/sub/mul)