Subscribe on changes!

effect memory leak

avatar
Nov 11th 2022

What problem does this feature solve?

test('effect memory leak', () => { const original = { foo: 1, bar: 1 } const original2 = { bar: 1 } const state = reactive(original) const state2 = reactive(original2)

let count1 = 0
let count2 = 0
effect(() => {
  count1++
  state.foo
  effect(() => {
    state2.bar
    count2++
  })
  state.bar
})
state.foo++
expect(count1).toBe(2)
expect(count2).toBe(2)
state.bar++
expect(count1).toBe(3)
expect(count2).toBe(3)
state2.bar++
expect(count1).toBe(3)
expect(count2).toBe(4)  // The value of the expected quantity ended up being 4, but it became 6 ,Outer dependencies 
 trigger updates that cause memory dependencies to collect the same content, will memory leaks occur in some scenarios?

})

What does the proposed API look like?

Is there a security issue with this?