FAQ

On Saturday, November 8, 2014 2:37:10 AM UTC+1, nicolas...@gmail.com wrote:
When a finalizer function is set with runtime.SetFinalizer(), it is run in
a dedicated goroutine, after GC has finished its work.
It means that the finalizer function runs in parrallel with the main and
other threads of the program.
This little program illustrate this:
http://play.golang.org/p/KLrhppn5k5

This means that the finalizer function must be goroutine-safe (access to
shared memory must be synchronized).

But finalizers are often used to release resources.
I never use finalizer to release resources. Only use for finalizer is debug
and
I have special case when I need to make object alive (when referenced from
C code), by non stop resetting
finalizer until C code sets variable which indicates that object should be
collected.
eg user data that is referenced from C++ object which calls Go event
handling function.
But resource handling in finalizer is not good as finalizers are not run
immediately.
There is `defer` for that.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 6 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 8, '14 at 1:37a
activeNov 11, '14 at 4:09a
posts6
users6
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase