Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:53:54+00:00 2026-05-29T21:53:54+00:00

In Erlang, is it possible to have a cleanup function automatically called when all

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:53:56+00:00Added an answer on May 29, 2026 at 9:53 pm

    From the file documentation:

    IoDevice is really the pid of the process which handles the file. This process is linked to the process which originally opened the file. If any process to which the IoDevice is linked terminates, the file will be closed and the process itself will be terminated. An IoDevice returned from this call can be used as an argument to the IO functions (see io(3)).

    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:close to the terminate function. Of course your gen_* must be attached to a supervisor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to implement a closure in Erlang? For example, how would I
Is it possible to use wildcards in the Erlang compiler's -I option? For example,
Is it possible to trap Linux signals (e.g. SIGUSR1) through an handler in Erlang?
As you might know, it's now possible to trace Erlang functions by using the
I am working on Erlang robotic project. I have made a wallfollower robot program
is it possible to define a circular list in erlang? http://en.wikipedia.org/wiki/Linked_list first question would
I was reading the erlang documentation about file io and saw this: On operating
I have a Erlang webapp, based on Mochiweb and Mnesia, which consumes and emits
I have a server written in Erlang with a custom binary interface that gets
Is it possible to write an Antlr code generation target for Erlang?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.