Generally, binary will deallocate automaticly when the count reference is none, but how to deallocate binary in a single process,before the process terminated??
thanks a lot!!
Generally, binary will deallocate automaticly when the count reference is none, but how to
Share
Erlang uses reference counting for keeping track of where binaries are used. Whenever a process creates a binary, the count goes up, and whenever it is sent to another process, yet another increment is made. As the processes stop using the binary (i.e. don’t keep any variables bound to it anymore), the count will decrease.
Whether a binary is used by a single process or multiple ones doesn’t really matter, since when the reference count is zero, the binary is automatically garbage collected. Therefore, even if you only use the binary in a single process, the Erlang VM will handle it for you.
In fact, the general “rule” to apply is that a binary is, like any other data type in Erlang, automatically garbage collected.