SodiumFRP / sodium-typescript

Typescript/Javascript implementation of Sodium FRP (Functional Reactive Programming) library
124 stars 17 forks source link

Memory bounce in switchC/switchS #100

Closed clinuxrulz closed 5 years ago

clinuxrulz commented 5 years ago

This only applies to typescript for its unique (but nesassary) way of mananging memory.

These two lines in switchS and similar lines in switchC.

kill2();
kill2 = sa.listen_(out.getVertex__(), h2, true);

Notice how we are decrementing ref count of the previous inner vertex before incrementing the ref count on the next inner vertex. Any vertices that are the same in the long chain of vertices connect from the inner vertex could have a memory bounce, likewise for switching to the same inner vertex twice. Doing the increment ref count before the decrement ref count (swaping the order), could save the machine a bit of work.

clinuxrulz commented 5 years ago

If the ordering of the two lines are important, we can wrap a register and deregister on the outside of the disconnect/connect of the inner vertex.

clinuxrulz commented 5 years ago

Note this memory bounce is only observable in a situation we'd be making use of Cell::tracking . As we'd normally have a lambda1 somewhere keeping sodium objects alive that we may switch to.