Fork me on GitHub
#re-frame
<
2021-01-05
>
Lu01:01:19

I was wondering what happens if one subscribes from within a callback function i.e. on-click? Are any of the four subscription layers compromised at all?

p-himik03:01:20

It's somewhere in the FAQ I believe. It will create a leak since the subs will be cached but will never be pruned.

Lu09:01:30

I guess I don’t get the “it might not be freed”. It seems the mem leak happens by chance not for sure

p-himik09:01:06

If the sub is also used in a view, then it will be freed when the view is unmounted. If the sub is not used in any view, there will be a leak.

Lu11:01:52

Great! Thanks.

mikethompson06:01:27

@lucio The subscribe and the subsequent dereference should happen in the render phase. Not much later when an on-click handler is called.

👍 3