[erlang-questions] Memory management using erl_nif

Sverker Eriksson <>
Tue Mar 30 19:52:51 CEST 2010

I think you are trying to do something that is not currently possible, 
that is keeping a reference to a read-only binary between NIF calls. 
Only writable binaries obtained from enif_alloc_binary can be kept 
between calls. But as soon as you make terms out of them, they get 
read-only and in total control of the VM (garbage collector).
The only way to keep an inspected binary is to copy the content into a 
raw buffer or a writable binary.

/Sverker, Erlang/OTP

William v Doorn wrote:
> Hello again,
> First of all; sorry for my second question today, but I just can't get my
> head around it. I'm trying to write a simple pair of functions; one sets the
> binary, the other returns it. However it crashes at the get part. erl.exe
> crashes when trying to do niftest:get().
> Here is the source:
> http://gist.github.com/349316
> Thanks,
> William van Doorn

More information about the erlang-questions mailing list