Skip to main content

Module memory

Module memory 

Source
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.

macOSLinuxWindowsWeb
process_memoryproc_pid_rusage/proc/self/statusGetProcessMemoryInfoNone
peaklifetime max footprint– (None)PeakPagefileUsageNone
thread_countproc_pidinfo/proc/self/statustoolhelp snapshotNone
release_free_memoryno-op (see above)malloc_trim (glibc)no-opno-op

Structs§

ProcessMemory
Memory of this process, in bytes.

Functions§

process_memory
This process’s memory, or None where 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=1 in 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 None where the platform has no way to ask (the web) or the call failed.