In Erlang, is it possible to have a cleanup function automatically called when all references to a resource go away? For example, will the native file handle that is opened by calling file:open/2 ever be closed if file:close/1 is never called? If this is possible, how is it done? If not possible, are there Erlang idioms that make resources leaks like this not an issue?
In Erlang, is it possible to have a cleanup function automatically called when all
Share
From the
filedocumentation:So, if the process that opened the file dies, the file will be closed automatically.
If you are using OTP and you want to be absolutely sure your file was closed when your process dies, add
file:closeto theterminatefunction. Of course your gen_* must be attached to a supervisor.