Help us shape the future of Go! Take the 2026 Go Developer Survey

memguard

package
v0.10.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package memguard bounds a process's memory: it reads the process's peak resident size and reports when it passes a limit, so a runaway stops small and loud instead of taking the machine (0.10.13's re-embed passed 100 GB).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PeakRSS

func PeakRSS() int64

PeakRSS reports this process's peak resident memory in bytes, or 0 when it cannot be read. getrusage reports ru_maxrss in bytes on macOS and in kilobytes on Linux. A peak, not the current size: a process that has grown past its cap stops, which is what the cap is for.

func Watch

func Watch(limit int64, every time.Duration, rss func() int64, over func(used int64)) (stop func())

Watch samples rss every interval and calls over once, with the size read, the first time it is above limit. The returned stop ends sampling and waits for the sampler to exit; call it when the watched work is done. Once stop is called, over is not: work that finished is not reported. over must exit the process or return promptly, or stop waits for it. A limit of 0 or less, or a nil rss, turns the watch off.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL