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 6956161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:49:56+00:00 2026-05-27T14:49:56+00:00

The function runtime.SetFinalizer (x, f interface{}) sets the finalizer associated with x to f

  • 0

The function runtime.SetFinalizer(x, f interface{}) sets the finalizer associated with x to f.

What kind of objects are finalized by default?

What are some of the unintended pitfalls caused by having those objects finalized by default?

  • 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-27T14:49:56+00:00Added an answer on May 27, 2026 at 2:49 pm

    The following objects are finalized by default:

    • os.File: The file is automatically closed when the object is garbage collected.

    • os.Process: Finalization will release any resources associated with the process. On Unix, this is a no-operation. On Windows, it closes the handle associated with the process.

    • On Windows, it appears that package net can automatically close a network connection.

    The Go standard library is not setting a finalizer on object kinds other than the ones mentioned above.

    There seems to be only one potential issue that may cause problems in actual programs: When an os.File is finalized, it will make a call to the OS to close the file descriptor. In case the os.File has been created by calling function os.NewFile(fd int, name string) *File and the file descriptor is also used by another (different) os.File, then garbage collecting either one of the file objects will render the other file object unusable. For example:

    package main
    
    import (
        "fmt"
        "os"
        "runtime"
    )
    
    func open() {
        os.NewFile(1, "stdout")
    }
    
    func main() {
        open()
    
        // Force finalization of unreachable objects
        _ = make([]byte, 1e7)
        runtime.GC()
    
        _, err := fmt.Println("some text") // Print something via os.Stdout
        if err != nil {
            fmt.Fprintln(os.Stderr, "could not print the text")
        }
    }
    

    prints:

    could not print the text
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating some on runtime. For that I'm using this function: function creatediv(id, html,
How do I cast a parameter passed into a function at runtime? private object
If I do this stuff.addEventListener(FooEvent.NAME, function(e:FooEvent) { dispatchEvent(e); } I get a runtime error
Is there any way I can call CUDA runtime function calls such as cudaMemcpy(...);
I use the following types to create a new function at runtime: typedef int
At runtime I need to print out an address, and then find which function
it is possible to assign to a class variable a function at runtime to
Can we attach arraylist or function with a javascript object at runtime function abc(){
The Objective C runtime reference has the function class_getSuperclass for getting the superclass of
In python I can put a function into a variable at runtime, then call

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.