Erlang / Erlang Advanced Interview questions
What is the significance of the binary reference count and off-heap binary garbage collection?
Any binary larger than 64 bytes is allocated once, off the process heap, and shared by reference rather than copied whenever it's passed around within reach of the same underlying data (for instance, sub-binary matches, or being stored in multiple variables). A reference count tracks how many live references point to that off-heap blob.
flowchart LR
A[Large binary allocated off-heap, refcount=1] --> B[Process A holds a reference]
A --> C[Sub-binary match creates another reference, refcount=2]
B --> D[Process A garbage collected, its reference dropped, refcount=1]
C --> E[Last holder GC'd, refcount=0]
E --> F[Off-heap memory freed]
The blob is only actually freed once its reference count drops to zero, which only happens as a side effect of garbage collecting every process/reference that held a pointer to it. This is precisely why off-heap binaries can outlive what you'd naively expect from looking at process code alone — the memory isn't released the moment a variable "goes out of scope" the way it might in a language with deterministic destructors; it's released only when GC actually runs and drops the last reference.
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...
