Go Runtime's Persistent 128MB Heap Arenas Cause Excessive Memory Usage in CGO/Purego Calls: Solution Needed

go dev.to

Introduction Go's runtime has a peculiar quirk: it allocates 128MB heap arenas during foreign function calls (CGO/purego) and never releases them. This behavior, while intended for efficient memory management, becomes a critical issue in memory-sensitive workloads like database proxies. A real-world example illustrates the problem: a Go-based database proxy calling libSQL (a SQLite fork) via CGO exhibits 4.2GB RSS for a simple SELECT 1 query. macOS heap analysis reveals only 335KB all

Read Full Tutorial open_in_new
arrow_back Back to Tutorials