-
Notifications
You must be signed in to change notification settings - Fork 30
Description
If a computed c1 is created, associated to a state s1, then the c1 reference us dropped, garbage collection on c1 will be prevented until s1 is also dropped, because it is still referenced by liveConsumerNode of s1.
I can confirm this from my own observation on both Chrome and Firefox. It is easy to reproduce and I will post the demo code here asap.
It is the similar case when s1 is dropped but not c1 due to producerNode. It is also true for watchers but it can be manually unwatched and it is then collectable.
It could be a real problem for large graphs, especially when the whole graph is connected. No dropped nodes can be collected as long as there is a survivor.
Hopefully it won't be the case for the future native implementation. However this problem can really prevent this "polyfill" becoming truly usable.
I am suggesting two solutions here:
One is to use weakref. However it should be carefully decided when to use it or not. Eg. watchers should probably use strong refs so a state -> computed -> watcher chain won't drop the intermediate computed.
Another one is to allow manually disposing. There is a Symbol.dispose for that.
Maybe I should also suggest this explicitly management approach to the proposal if you like it.