Debugging memory usage of :cowboy_websocket.loop/3

Using the phoenix live dashboard, I am seeing these processes for all the channel users. But, it adds up if every user has this much memory usage. How can I reduce the memory usage? I am not sure how to go about searching for the cause of it.

So I just noticed this myself when looking at phoenix dashboard.

Looks like each connection is associated with a phoenix connection.

An active liveview session can take multiple MB of ram, but hibernates after 15 seconds.

After hibernation, it takes roughly 150kB of ram

The cowboy_websocket loop can actually be manually garbage collected and with my preliminary testing seems to be fine.

:erlang.garbage_collect(pid(0, 6050,0))

Since the memory will eventually be garbage collected, I don’t believe this is an issue, but perhaps it would be good to have the websocket handler also garbage collect when hibernating.