I understand the first part, but the second? Why is the finalizer function 
passed a reference to the object being finalized then?





-----Original Message-----
>From: Ian Lance Taylor <i...@golang.org>
>Sent: Aug 21, 2019 12:06 PM
>To: Robert Engels <reng...@ix.netcom.com>
>Cc: zct <tangzhongch...@bytedance.com>, golang-nuts 
><golang-nuts@googlegroups.com>
>Subject: Re: [go-nuts] A problem about runtime.SetFinalizer
>
>On Wed, Aug 21, 2019 at 9:14 AM Robert Engels <reng...@ix.netcom.com> wrote:
>>
>> Seems like GoLint should emit an 'unused parameter' in this case.
>
>It's normal for a function to have an unused parameter.  And in
>particular it's normal for a finalizer to not refer to the object
>being finalized.
>
>Ian
>
>
>> -----Original Message-----
>> From: zct
>> Sent: Aug 21, 2019 10:50 AM
>> To: golang-nuts
>> Subject: Re: [go-nuts] A problem about runtime.SetFinalizer
>>
>> I got it.Thank you for your help
>>
>> 在 2019年8月21日星期三 UTC+8下午11:00:26,Ian Lance Taylor写道:
>>>
>>> On Wed, Aug 21, 2019 at 5:55 AM zct <tangzho...@bytedance.com> wrote:
>>> >
>>> > I recently had  a goroutine leak problem, the code i reduced is like 
>>> > this: https://play.golang.org/p/YW4hWoZZ7CD.
>>> >
>>> > The program is long-running and the finalizer is not called
>>> >
>>> > The RoomObj is deleted from map, why was it not released? Is it refereed 
>>> > by the asyncChan object?
>>> >
>>> >  I don't understand here, can somebody explain the reason
>>>
>>> Your finalizer itself is keeping the value alive.
>>>
>>> runtime.SetFinalizer(a, func(r *RoomTest) {
>>>     fmt.Println("SetFinalizer")
>>>     close(a.asyncChan.a)
>>> })
>>>
>>> You need to write the finalizer function to refer to r, not a.  The
>>> reference to a in the finalizer function ensures that a is always
>>> live.
>>>
>>> Ian
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/906c3d64-9211-4206-a2ee-1a0d881a35b7%40googlegroups.com.
>>
>>
>>
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/821137931.4341.1566404048080%40wamui-kitty.atl.sa.earthlink.net.
>
>-- 
>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+unsubscr...@googlegroups.com.
>To view this discussion on the web visit 
>https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUjmy8%2BMPageq73sjWOR792mkXtLbGtwg6jfB_76R2R1Q%40mail.gmail.com.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2086058808.5386.1566407889031%40wamui-kitty.atl.sa.earthlink.net.

Reply via email to