FAQ
Today I discovered a tricky situation with Finalizers where using a closure
can cause it to not run.

http://play.golang.org/p/QWn904819Y

Basically this finalizer will not run because /a/ is referenced instead of
/b/:

...this won't run...

runtime.SetFinalizer(a, func(b *Foo) {
fmt.Println("Finalize", a)
})
...this will...
runtime.SetFinalizer(a, func(b *Foo) {
fmt.Println("Finalize", b)
})

I don't think this is a bug because the SetFinalizer() documentation /does/
mention cyclic structures, but I just wanted to kind of warn/let others
know about this exact case.

Stephen

--
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

  • Dmitry Vyukov at Mar 13, 2014 at 8:52 am
    Maybe govet can detect it?


    On Thu, Mar 13, 2014 at 11:31 AM, Stephen Gutekanst
    wrote:
    Today I discovered a tricky situation with Finalizers where using a closure
    can cause it to not run.

    http://play.golang.org/p/QWn904819Y

    Basically this finalizer will not run because /a/ is referenced instead of
    /b/:
    ...this won't run...

    runtime.SetFinalizer(a, func(b *Foo) {
    fmt.Println("Finalize", a)
    })


    ...this will...

    runtime.SetFinalizer(a, func(b *Foo) {
    fmt.Println("Finalize", b)
    })

    I don't think this is a bug because the SetFinalizer() documentation /does/
    mention cyclic structures, but I just wanted to kind of warn/let others know
    about this exact case.

    Stephen

    --
    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.
    --
    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.
  • Stephen Gutekanst at Mar 14, 2014 at 3:16 am
    Just tried, 'go tool vet' doesn't mention anything about it.

    Stephen
    On Thursday, March 13, 2014 1:51:47 AM UTC-7, Dmitry Vyukov wrote:

    Maybe govet can detect it?


    On Thu, Mar 13, 2014 at 11:31 AM, Stephen Gutekanst
    <stephen....@gmail.com <javascript:>> wrote:
    Today I discovered a tricky situation with Finalizers where using a closure
    can cause it to not run.

    http://play.golang.org/p/QWn904819Y

    Basically this finalizer will not run because /a/ is referenced instead of
    /b/:
    ...this won't run...

    runtime.SetFinalizer(a, func(b *Foo) {
    fmt.Println("Finalize", a)
    })


    ...this will...

    runtime.SetFinalizer(a, func(b *Foo) {
    fmt.Println("Finalize", b)
    })

    I don't think this is a bug because the SetFinalizer() documentation /does/
    mention cyclic structures, but I just wanted to kind of warn/let others know
    about this exact case.

    Stephen

    --
    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...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    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.
  • Dmitry Vyukov at Mar 14, 2014 at 5:47 am
    Sorry, I meant that govet can be extended to catch this. Please file an issue at
    https://code.google.com/p/go/issues/entry



    On Fri, Mar 14, 2014 at 7:16 AM, Stephen Gutekanst
    wrote:
    Just tried, 'go tool vet' doesn't mention anything about it.

    Stephen

    On Thursday, March 13, 2014 1:51:47 AM UTC-7, Dmitry Vyukov wrote:

    Maybe govet can detect it?


    On Thu, Mar 13, 2014 at 11:31 AM, Stephen Gutekanst
    wrote:
    Today I discovered a tricky situation with Finalizers where using a
    closure
    can cause it to not run.

    http://play.golang.org/p/QWn904819Y

    Basically this finalizer will not run because /a/ is referenced instead
    of
    /b/:
    ...this won't run...

    runtime.SetFinalizer(a, func(b *Foo) {
    fmt.Println("Finalize", a)
    })


    ...this will...

    runtime.SetFinalizer(a, func(b *Foo) {
    fmt.Println("Finalize", b)
    })

    I don't think this is a bug because the SetFinalizer() documentation
    /does/
    mention cyclic structures, but I just wanted to kind of warn/let others
    know
    about this exact case.

    Stephen

    --
    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...@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    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.
    --
    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.
  • Stephen Gutekanst at Mar 14, 2014 at 8:00 pm
    No problem, filed.

    https://code.google.com/p/go/issues/detail?id=7546

    Stephen
    On Thursday, March 13, 2014 10:47:14 PM UTC-7, Dmitry Vyukov wrote:

    Sorry, I meant that govet can be extended to catch this. Please file an
    issue at
    https://code.google.com/p/go/issues/entry



    On Fri, Mar 14, 2014 at 7:16 AM, Stephen Gutekanst
    <stephen....@gmail.com <javascript:>> wrote:
    Just tried, 'go tool vet' doesn't mention anything about it.

    Stephen

    On Thursday, March 13, 2014 1:51:47 AM UTC-7, Dmitry Vyukov wrote:

    Maybe govet can detect it?


    On Thu, Mar 13, 2014 at 11:31 AM, Stephen Gutekanst
    wrote:
    Today I discovered a tricky situation with Finalizers where using a
    closure
    can cause it to not run.

    http://play.golang.org/p/QWn904819Y

    Basically this finalizer will not run because /a/ is referenced
    instead
    of
    /b/:
    ...this won't run...

    runtime.SetFinalizer(a, func(b *Foo) {
    fmt.Println("Finalize", a)
    })


    ...this will...

    runtime.SetFinalizer(a, func(b *Foo) {
    fmt.Println("Finalize", b)
    })

    I don't think this is a bug because the SetFinalizer() documentation
    /does/
    mention cyclic structures, but I just wanted to kind of warn/let
    others
    know
    about this exact case.

    Stephen

    --
    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...@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    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...@googlegroups.com <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 13, '14 at 7:31a
activeMar 14, '14 at 8:00p
posts5
users2
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase