<div dir="ltr"><br><div><br></div><div>I have following code in nif:</div><div><br></div><div>State *s = enif_alloc_resource(..)</div><div>enif_self(env, &s->owner);<br></div><div>ERL_NIF_TERM term = enif_make_resource(env, s);<br>enif_release_resource(s);<br></div><div>return term;</div><div><br></div><div><br></div><div>Then later another thread (not written by me) is calling my callback function:</div><div><br></div><div><br></div><div>void mycallback(void *obj)</div><div>{</div><div>  State *s = obj;</div><div>  ErlNifEnv *msg_env = enif_alloc_env();<br></div><div>  ERL_NIF_TERM term = enif_make_resource(msg_env, s);</div><div>  enif_send(NULL, &s->owner, msg_env, term);</div><div>  enif_free_env(msg_env);</div><div>}</div><div><br></div><div><br></div><div>Is this code correct?</div><div><br></div><div>Should I put release_resource for each make_resource or only for release_resource?</div><div><br></div><div>Is this calling of enif_send correct?</div><div><br></div><div>I'm afraid that I miss these answers in documentation or cannot find them. </div><div><br></div><div>  </div></div>