4

I'm using Om for the client side and through the lifetime of the application many components gets mounted/unmounted. When mounted, various channels are opened (in go blocks). And I'm planning to use IWillUnmount to close them too. But first, my questions are: What happens to unclosed channels? Do the resources they used get released? Not closing channels (when unmounting components) can degrade the browser performance in the longrun? Thanks.

roboli
  • 1,220
  • 16
  • 24

1 Answers1

3

Based on a cursory reading of the implementation, unclosed channels should not use resources if they are eligible to be garbage collected. That means that both the sender and receiver cannot retain references to them (or must also be eligible for collection).

All closing a channel does is empty its buffer, and mark it closed so that nothing can be added to the buffer. If it doesn't have any messages in its buffer, an open channel will use the same resources as a closed one.

https://github.com/clojure/core.async/blob/master/src/main/clojure/cljs/core/async/impl/channels.cljs#L110

Derek Slager
  • 12,511
  • 3
  • 29
  • 34
Walton Hoops
  • 794
  • 3
  • 14