tango icon indicating copy to clipboard operation
tango copied to clipboard

struct context maybe cause memory leak?

Open u0x01 opened this issue 6 years ago • 1 comments

memory leak in this case:

   24.51MB  1.77% 20.68%   327.24MB 23.58%  net/http.readRequest
  258.23MB 18.61% 39.29%   283.23MB 20.41%  net/textproto.(*Reader).ReadMIMEHeader

leak

see more: https://github.com/gorilla/sessions see more: https://pathbox.github.io/2017/05/27/find-the-reason-memory-leak/

Important Note: If you aren't using gorilla/mux, you need to wrap your handlers with 
context.ClearHandler or else you will leak memory! An easy way to do this is to wrap the top-level mux when calling http.ListenAndServe:

http.ListenAndServe(":8080", context.ClearHandler(http.DefaultServeMux))
The ClearHandler function is provided by the gorilla/context package.

More examples are available on the Gorilla website.

u0x01 avatar Jul 11 '18 03:07 u0x01

Could you give more testing details?

lunny avatar Nov 02 '18 01:11 lunny