baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript
https://baconjs.github.io
MIT License
6.47k stars 331 forks source link

Closures memory leak #446

Closed GianlucaGuarini closed 9 years ago

GianlucaGuarini commented 9 years ago

I think the following bug is not really just a Bacon.Model issue but it is more related to the Baconjs core https://github.com/baconjs/bacon.model/issues/10 Any possible solution?!

raimohanska commented 9 years ago

Can you demonstrate the problem with Bacon.js core only?

The 2-way bindings in Bacon.Model may very well be prone to memory leaks. At least it's known that there's no way to "unbind".

GianlucaGuarini commented 9 years ago

I have written my own Bacon model but I got the same issue. In my case the Bacon.Bus class is leaking. The newest version 0.7.28 does not really solve the problem. It seems that there is too much memory allocated in the closures created using the onValue method. I will create a simpler example to demonstrate the issue

GianlucaGuarini commented 9 years ago

Despite the new releases and the new memory performance tests, according to my new test the heap memory usage is still pretty high, any idea? http://jsfiddle.net/gianlucaguarini/ekm716c9/ 63.1 MB for 5000 Bacon.Bus * 4 subscribers

screen shot 2014-12-11 at 08 28 27

I think probably the issue could be in the javascript file compiled, coffeescript creates too many closures

GianlucaGuarini commented 9 years ago

I will write a similar example using RxJS to see if it has the same problem

raimohanska commented 9 years ago

Could you provide a JSFiddle or something similar to demonstrate the issue? Would make it easier to find out if there's a leak or not.

GianlucaGuarini commented 9 years ago

It's right on my previous post :smile: I will post it again http://jsfiddle.net/gianlucaguarini/ekm716c9/

GianlucaGuarini commented 9 years ago

I wrote the same code using RxJS and it uses just 14.3 MB. RxJS uses a lot less memory (-77%) to achieve the same result!

http://jsfiddle.net/gianlucaguarini/e497s5yg/

screen shot 2014-12-11 at 21 12 19

raimohanska commented 9 years ago

That's pretty much expected, based on earlier memory footprint tests. There's still a lot of fat in Bacon. So if you need to minimize memory footprint, you should consider RxJs or Kefir at the moment.

puppetmaster3 commented 7 years ago

Any updates on this?

GianlucaGuarini commented 7 years ago

@puppetmaster3 I recently tried stroxy by my friend @nilssolanki using native ES2015 Proxies. The results are much better and the memory footprint is ~95% smaller maybe bacon.js could consider switching to proxies as well