yew icon indicating copy to clipboard operation
yew copied to clipboard

Cycle between `Scope` and `ComponentState`

Open Diggsey opened this issue 3 years ago • 3 comments

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.

Diggsey avatar May 02 '21 16:05 Diggsey

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:

  • Scopes 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.

Diggsey avatar May 05 '21 21:05 Diggsey

Maybe running some tests in Miri could help?

lukechu10 avatar May 06 '21 03:05 lukechu10

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.

mc1098 avatar Sep 22 '21 08:09 mc1098