From ea4d1f681babbce9545c9c5f3d5194a789c89f5b Mon Sep 17 00:00:00 2001 From: Gary Burd Date: Tue, 20 Jun 2017 12:01:03 -0700 Subject: [PATCH] Reduce memory used in chat example --- examples/chat/client.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/chat/client.go b/examples/chat/client.go index 2646847..ecfd9a7 100644 --- a/examples/chat/client.go +++ b/examples/chat/client.go @@ -129,6 +129,9 @@ func serveWs(hub *Hub, w http.ResponseWriter, r *http.Request) { } client := &Client{hub: hub, conn: conn, send: make(chan []byte, 256)} client.hub.register <- client + + // Allow collection of memory referenced by the caller by doing all work in + // new goroutines. go client.writePump() - client.readPump() + go client.readPump() }