Memory leak - htop shows that the beam processes are using up all memory and the swap file

I arrive slightly confused. My application is eating up all available memory. I tried to look through observer or recon and I don’t see anything. The application does not consume memory, but htop shows that the beam processes are using up all memory and the swap file

recon:node_stats_print(1, 100).
erl -version
Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version

Erlang/OTP 25 [erts-] [source] [32-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]

which way to look?

Please look at Chapter 7 (Memory Leaks) of Erlang in Anger. I believe it will guide you to find out what’s going on.


I read this book first, but everything is fine with the code, a similar problem occurs when I try to run my code as a linux service in systemd

If you just run your system as a regular application from the command line you do not see this memory leakage? It only leaks when executed via systemd? That would be quite unusual (but interesting) if true.

it looks strange, if I run it as a linux daemon, memory starts to grow, but if I run it as bin /app foreground everything is fine, perhaps there is some kind of peculiarity in launching the erlang daemon

I had the same problem when I tried to run the script via rc.local

Could this be memory fragmentation and not actual memory consumption? I’ve seen Linux VMs report 90% memory utilized while the application reports its using much less. Once traffic dies down the memory utilization also decreases.

I disabled all application consumption. My general server starts empty, it doesn’t work and memory still leaks.

Did you try the noshell option when you start as daemon?

no I haven’t tried it

It leaves your server running as a foreground process, but without the interactive EShell. It can help when you start from another process. In zotonic we have an option for that to run in docker.

I think rebar3 does it for me. I’m doing a release of rebar3 and running it as myapp foreground. Correct me if this is not true

For some reason, 24 applications are launched at once, is this how it should be?

No, that is how Linux lists multi-threaded programs with ps or htop. It’s been like that for decades. A bit weird… linux - Why are there many processes listed under the same title in htop? - Super User

Yes that’s right. I try to launch the application manually, the consumption is 93M and is stable, I launch it as a service, the memory starts to grow.

launched in the console

As you can see, memory consumption begins

After some experimentation, I see that the problem occurs with the fact that I am capturing output to the console. If I stop outputting to the console, then the memory consumption does not increase. It remains to understand how I can correctly display on the screen from an application running as a service


You can always connect to long running process and inspect it with a remote shell.

this is not what I want, I display information on the monitor via ncurses and this seems to be the problem