Does an Elixir process die when there are no more references to its PID?

361 views Asked by At

New to Elixir and OTP. Trying some hello-world examples with GenServer. I'm writing tests where each test spawns a GenServer process. They are not explicitly terminated. Will the process die after the test finishes?

Follow up: If it's not terminated, do they turn into "zombie" process? Also, is there a pattern for terminating them after the test completes?

1

There are 1 answers

0
michalmuskala On BEST ANSWER

No, processes are not garbage collected. Yes, they turn into "zombie" processes.

The pattern to prevent that is to link the processes. When one linked process terminates - all linked processes will terminate too. So if you start your server using GenServer.start_link from the test process - this will link the server process to the test process and when the test exists, the server will exit too.