tenderowls / moorka

ABANDONED
21 stars 5 forks source link

WeakReference is not weak in JavaScript #22

Closed fomkin closed 9 years ago

fomkin commented 9 years ago

Epic fail. What should I do?

val a = Var("")
val b = Var("")
val c = Var("")

val g = a flatMap { a => 
  b flatMap { b => // This
    c map { c => // And this. Will leak on every update of g binding
      a + b + c
    }
  }
}
Lovesan commented 9 years ago

Учитывая, что циклов в графе у нас быть не может, строго говоря, можно попробовать Reference Counting, как в COM, или там как в Python старом, или как в умных указателях в C++

fomkin commented 9 years ago

@Lovesan Speak english please. This is a public repo. Ok. How are you going to implement reference counting in Scala?

fomkin commented 9 years ago

Solution

val g = reaper mark {
  a flatMap { a => 
    b flatMap { b => 
      c flatMap { c =>
        a + b + c
      }
    }
  }
}

On every run kill dependent binding which is not marked by reaper.