[erlang-questions] enif_alloc_resource and enif_release_resource

Sverker Eriksson sverker@REDACTED
Mon Mar 12 12:15:26 CET 2012

Daniel Goertzen wrote:
> Am I allowed to call enif_release_resource() immediately after
> calling enif_alloc_resource().  The documentation suggests that I should be
> calling enif_make_resource() in between, but I don't want to do that.
Calling enif_release_resource() immediately after enif_alloc_resource() 
is fine and will destruct the resource. This is very common in error 

IF you want to create a "resource-term" then you must do that by calling 
enif_make_resource() _before_ enif_release_resource().

> Furthermore, on a resource that I just allocated with enif_alloc_resource,
> is there a way to release it without invoking the destructor?
No. The destructor will always be called if the resource type has one.
You can of course have your own "non-initialized" state that makes your 
destructor do nothing.

/Sverker, Erlang/OTP Ericsson

More information about the erlang-questions mailing list