Does limiting old‑generation heap size with +hms prevent memory leaks in long‑running Elixir processes?
0 reputation · 09 Apr 2020, 22:47 UTC
0 reputation · 09 Apr 2020, 22:47 UTC
The goal is to determine whether imposing a hard limit on the old‑generation heap size via the BEAM flag +hms reliably prevents the unbounded memory growth that characterizes leaks in long‑running Elixir processes. Such leaks often stem from large binaries, ETS tables, or global process dictionaries that survive minor collections and accumulate in the old generation.
Constraints include the necessity to restart the node to apply +hms, the global effect on all processes, and the risk that frequent old‑gen collections may degrade performance or merely hide the leak rather than eliminate it. It is also unclear how the flag interacts with leaks that involve resources not reclaimed by garbage collection, such as open file descriptors or native resources.
Does the +hms flag actually stop old‑generation heap growth when the leak resides in binary data that is not subject to GC? If the flag triggers premature old‑gen collections, does it merely mask the leak or reduce observable memory growth without fixing the root cause?
35275 reputation · 10 Apr 2020, 07:32 UTC
No, the +hms flag does not prevent memory leaks. It imposes a hard limit on the old-generation heap size, but it cannot stop the underlying cause of a leak or reclaim memory that is still reachable by the BEAM virtual machine.
The +hms flag defines a ceiling for the old-generation heap. When the heap reaches this limit, the VM is forced to trigger a major (full-sweep) garbage collection to attempt to reclaim space. This creates two distinct scenarios depending on the nature of the leak:
+hms may keep memory usage stable by forcing more frequent collections. However, this is a mitigation of symptoms, not a fix for the root cause.It is important to distinguish between the BEAM heap and other memory areas. The +hms flag does not affect the following:
To verify if +hms is masking a leak or failing to stop one, follow these steps:
+hms and monitor the old-generation heap size using :erlang.memory() or the observer tool. Confirm unbounded growth.+hms set to a value slightly above your expected steady-state usage.Missing Diagnostic: To provide a more specific recommendation, please clarify if your memory growth is appearing as binary, ets, or process memory in your :erlang.memory() output.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.