[erlang-questions] enif_get_resource and reference counting

Daniel Goertzen <>
Sat Jan 9 22:20:16 CET 2016

enif_get_resource() does not increase the reference count.  You can think
of the term representing the resource as counting as a reference, so as
long as the term and its environment are alive then the resource will not
be destroyed.  In the example you have above you can skip the
keep()/release() because the resource term w/environment keeps it alive.

On Sat, Jan 9, 2016 at 12:12 AM John Doe <> wrote:

> Hi,
> Does successful call of enif_get_resource increase reference counter on a
> resource, like  enif_keep_resource does?
> Or It is neccessary to do
> enif_get_resource(...);
> enif_keep_resource(...);
> ...some job...
> enif_release_resource(...);
> And if it does not increment the counter, can the resource become
> destroyed in the another thread between calls to enif_get_resource and
> enif_keep_resource?
> I'm afraid of race condition there.
> _______________________________________________
> erlang-questions mailing list
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160109/57e72991/attachment.html>

More information about the erlang-questions mailing list