Expand description
How much memory this process uses, and giving freed memory back to the system.
process_memory reads the numbers the OS’s own tools show: on macOS the footprint
(Activity Monitor’s “Memory” column, footprint <pid>: dirty private memory including
compressed and GPU memory the process owns) and the resident size; on Linux the private
resident plus swapped memory and the resident size (/proc/self/status); on Windows the
private commit and the working set. Where the OS keeps it, it also gives the highest footprint
since the process started, so a short spike between two readings still counts.
thread_count says how many threads the process runs.
release_free_memory asks the allocator to return pages it holds free. Where that works
(glibc’s malloc_trim) it shrinks the process at once. On macOS it does nothing: the system
call for it (malloc_zone_pressure_relief) releases next to
nothing (measured: 0–49 KB after freeing gigabytes): the default allocator keeps freed small
and medium regions dirty for reuse and the kernel takes them back by itself over the next
30–60 s. A process started with MallocSpaceEfficient=1 in its environment hands freed
regions back at once (a bundled app sets it through LSEnvironment in its Info.plist);
space_efficient_malloc says whether this one was. Call it after dropping caches, not per
frame.
| macOS | Linux | Windows | Web | |
|---|---|---|---|---|
process_memory | proc_pid_rusage | /proc/self/status | GetProcessMemoryInfo | None |
| peak | lifetime max footprint | – (None) | PeakPagefileUsage | None |
thread_count | proc_pidinfo | /proc/self/status | toolhelp snapshot | None |
release_free_memory | no-op (see above) | malloc_trim (glibc) | no-op | no-op |
Structs§
- Process
Memory - Memory of this process, in bytes.
Functions§
- process_
memory - This process’s memory, or
Nonewhere the platform has no way to ask (the web) or the call failed. - release_
free_ memory - Return the allocator’s free pages to the system where the allocator can (glibc’s
malloc_trim). Returns the bytes released where the allocator says; 0 everywhere today (macOS has nothing that works, see the module docs; glibc does not say). - space_
efficient_ malloc - Whether macOS’s allocator runs in its space-efficient mode (
MallocSpaceEfficient=1in the environment the process started with), which returns freed memory to the system at once. Always false elsewhere. - thread_
count - How many threads this process runs, or
Nonewhere the platform has no way to ask (the web) or the call failed.