Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak when using linked processes #1384

Open
danifv opened this issue Dec 4, 2024 · 3 comments
Open

Possible memory leak when using linked processes #1384

danifv opened this issue Dec 4, 2024 · 3 comments

Comments

@danifv
Copy link

danifv commented Dec 4, 2024

I'm doing some measurements on resource usage (memory and power mainly) and found a possible memory leak.
When spawning linked processes that end normally, the available Free Heap is lower than before starting the processes.
e.g.

f() ->
    [spawn_link(fun() ->  timer:sleep(500) end) || _ <- lists:seq(1, 50)].

In contrast, when spawning linked processes that terminate, the available Free Heap is more or less the same as before starting the processes.
e.g.

f() ->
    [spawn(fun() ->  ephemeral_start() end) || _ <- lists:seq(1, 50)].

ephemeral_start() ->
    spawn_link(fun() -> ephemeral() end).

ephemeral() ->
    timer:sleep(500),
    exit(normal).

I suspect, that memory related to the link remains allocated.

I'm doing the measurements on an ESP32 system.

@pguyot
Copy link
Collaborator

pguyot commented Dec 5, 2024

Is this related to this comment?

// TODO: we should scan for existing monitors when a context is destroyed

@danifv
Copy link
Author

danifv commented Dec 5, 2024

It could possibly be if that code also relates to links.
However I can confirm that a similar leak also occurs when monitoring spawned processes:

f() ->
    Pids = [spawn(fun() -> timer:sleep(500) end) || _ <- lists:seq(1,N)],
    [erlang:monitor(process, P) || P <- Pids].

@pguyot
Copy link
Collaborator

pguyot commented Dec 6, 2024

Links are handled internally there, this is the case where monitor->ref_ticks == 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants