<div dir="ltr">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.<div><br></div><div>I'm assuming R2 refers to an O2 which in turn is referring to an O1.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Sep 5, 2017 at 11:58 AM Benoit Chesneau <<a href="mailto:bchesneau@gmail.com">bchesneau@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">How do you manage the lifetime of a nif resource when it has been created and can be used by one another?<br>
<br>
1) I an object O1 and expose it as a resource R1<br>
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<br>
<br>
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 :)<br>
<br>
- benoît<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div>