reactive-banana icon indicating copy to clipboard operation
reactive-banana copied to clipboard

RFC: pulse parents are not really weak references

Open mitchellwrosen opened this issue 7 years ago • 2 comments
trafficstars

Hi, I have some code attached to a question I have about the implementation. It seems to me that a pulse child will always keep its pulse parent alive, yet the parents field is a [Weak SomeNode]. So, I changed this to a [SomeNode] and chased down all of the type errors.

Does this change make sense? Thanks.

mitchellwrosen avatar Jun 02 '18 00:06 mitchellwrosen

I would have to look this up in my notes again, but the overall idea is that neither should a child keep the parent alive, nor the other way round. The reasoning is:

  1. If an external source for events (AddHandler) no longer has any event occurrences, then it can be garbage collected. Repeat this process with as many children as possible. (The process ends when unionWith was applied.)
  2. If an internal event no longer leads to an observable output (this happens when using switchE or when not using reactimate), then it can be garbage collected. Repeat with as many parents as possible.

I don't quite remember what the current code does exactly, but the idea is too keep both children and parents as weak pointers, for reasons of symmetry. It may be that the current code actually ignores one of the two cases (number 1) because it was easier to implement. I dimly remember that only one of the two cases had to be done explicitly, while the garbage collector could handle the other one, but one had to make an explicit choice.

Sorry for the incomplete answer, this stuff is actually quite tricky.

HeinrichApfelmus avatar Jun 04 '18 16:06 HeinrichApfelmus

Interesting! I think you are correct that case 1 is not currently handled by the code, per the line line I deleted from connectChild:

mkWeakNodeValue child (P parent)

mitchellwrosen avatar Jun 04 '18 17:06 mitchellwrosen