yew
yew copied to clipboard
Cycle between `Scope` and `ComponentState`
Problem
There appears to be a cycle between the Scope
and ComponentState
types, since each contains an Rc<_>
to the other.
I couldn't see anywhere that explicitly breaks the loop, so I'm guessing this causes a memory leak.
Having worked with the codebase a bit more, I believe this is incorrect: the cycle is broken when a component is unmounted.
That said, it would probably be a good idea to have some tests for leaks (I have a crate mockalloc which may help with this) and/or to document the design itself, which AFAICT is:
-
Scope
s are created for each layer internally. - Each scope contains a strong reference to its parent.
- Each scope contains a strong reference to the component state, which is explicitly broken when the component is unmounted.
- Component states contain a strong reference to their scope.
Maybe running some tests in Miri could help?
That said, it would probably be a good idea to have some tests for leaks (I have a crate mockalloc which may help with this)
Maybe running some tests in Miri could help?
Both sound like great suggestions to me but I think they are owed their own respective issues :)
I've removed the bug label in favour of documentation because I think we should add some comments about this design.