[erlang-questions] nif resource lifetime

Daniel Goertzen <>
Tue Sep 5 19:50:21 CEST 2017


When forming R2 you would call enif_keep_resource(&O1), and the R2
destructor would enif_release_resource(&O1).  This assures O1 sticks around
while R2 is alive even if R1 dies.

I'm assuming R2 refers to an O2 which in turn is referring to an O1.


On Tue, Sep 5, 2017 at 11:58 AM Benoit Chesneau <> wrote:

> How do you manage the lifetime of a nif resource when it has been created
> and can be used by one another?
>
> 1) I an object O1 and expose it as a resource R1
> 2) I’m created R2 that need the object O1exposed by R1 by passing R1 as an
> argument to the nif function used to create R2
>
> I would like to make sure that the object is not preemptively killed or
> garbaged collected. How would you do it? Any feedback is welcome :)
>
> - benoît
> _______________________________________________
> 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/20170905/ef10a5ca/attachment.html>


More information about the erlang-questions mailing list