<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>close on Golang</title><link>https://golang.k5kc.com/tags/close/</link><description>Recent content in close on Golang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:15:00 +0530</lastBuildDate><atom:link href="https://golang.k5kc.com/tags/close/index.xml" rel="self" type="application/rss+xml"/><item><title>Need not close every channel</title><link>https://golang.k5kc.com/2020/08/16/need-not-close-every-channel/</link><pubDate>Sun, 16 Aug 2020 00:15:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/need-not-close-every-channel/</guid><description>You don&amp;rsquo;t need to close channel after using it, and it can be recycled automatically by the garbage collector. The following quote is from The Go Programming Language:
You needn&amp;rsquo;t close every channel when you&amp;rsquo;ve finished with it. It&amp;rsquo;s only necessary to close a channel when it is important to tell the receiving goroutines that all data have been sent. A channel that the garbage collector determines to be unreachable will have its resources reclaimed whether or not it is closed.</description></item><item><title>nil channel VS closed channel</title><link>https://golang.k5kc.com/2020/08/16/nil-channel-vs-closed-channel/</link><pubDate>Sun, 16 Aug 2020 00:15:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/nil-channel-vs-closed-channel/</guid><description>The zero value of channel type is nil, and the send and receive operations on a nil channel will always block. Check the following example:
package main import &amp;#34;fmt&amp;#34; func main() { var ch chan int go func(c chan int) { for v := range c { fmt.Println(v) } }(ch) ch &amp;lt;- 1 } The running result is like this:
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan send (nil chan)]: main.</description></item></channel></rss>