Fixed Cell memory leak in signaled subscriptions #32
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using input signals with subscriptions (layer 3 - materialized views) I've noticed gradually degraded responsiveness in a UI that subscribed to many of these form of subscriptions.
Upon investigation, and with the help of the Flutter Dev Tools, I've identified an issue that seemed to point to a memory leak of
Cell
instances:And indeed after some debugging, I've confirmed that when re-dash subscriptions were used as input signals, they created new
Cell
instances each time the signal gets resolved to a new value, and the oldCell
was not garbage collected (probably because it remained referenced by its original dependencies)This is corrected in this PR by introducing a signal cache (a registry if you will, like we use for normal subscriptions registered with
reg-sub
, but only for subscription signals)This is managed internally by re-dash (as with all other regsitries) no changes required to existing code.
Result is much better UI responsivenes that does not degrade over time, and Flutter Dev Tools agree: