Erlang / Erlang Advanced Interview questions
How do you troubleshoot a memory leak caused by large binaries not being garbage collected?
Large (>64 byte) binaries live off the process heap and are reference-counted, but the counter only drops when the owning process's heap is actually garbage collected — a process that receives many large binaries but rarely triggers a GC cycle (because its own small heap of local variables never fills up) can hold references to megabytes of off-heap binary data far longer than expected.
%% inspect suspects erlang:process_info(Pid, binary). %% list of {BinId, Size, RefCount} recon:bin_leak(10). %% recon helper: top 10 processes by binary refs
Common fixes:
- Force a GC explicitly on long-lived, low-activity processes holding binaries via
erlang:garbage_collect(Pid), either periodically or after processing a large payload. - Shrink the reference's lifetime — if only a small slice of a large binary is actually needed
long-term, copy just that slice with
binary:copy/1so the full original can be released. - Check for accidental retention in a process dictionary entry or long-lived accumulator that's never cleared.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
