Does Pulseaudio leak memory?
In your example, pulseaudio
is using 32MB not 3GB. The RES
column is physical memory. The VIRT
column shows all the virtual memory used by the process. According to man top
, that includes all code, data, and shared libraries plus pages that have been swapped out and pages that have been mapped but not used.
You can see more details on the virtual memory usage using the pmap tool:
pmap $(pidof pulseaudio) | sort -hk 2
00005590f6f0a000 4K r---- pulseaudio
00005590f6f0b000 4K rw--- pulseaudio
00007f50ea53f000 4K r---- libicudata.so.66.1
00007f50ea540000 4K r-x-- libicudata.so.66.1
....
00007f50e0000000 65536K rw-s- memfd:pulseaudio (deleted)
00007f50f314b000 65536K rw-s- memfd:pulseaudio (deleted)
total 1679768K
For me, most of the memory used is 64MB memfd
buffers. memfd
is a method of communicating between processes, and it is used by applications to transfer audio data to pulseaudio.
Even though the virtual memory for the buffers is allocated for each application, actual memory is only used to the amount of data currently in transit. When application writes audio samples to the buffer, memory is allocated for it. Once pulsaudio has mixed and played the samples, the memory is again released.