r/learnjavascript • • Oct 23 '17

JavaScript's Promise Leaks Memory

https://alexn.org/blog/2017/10/11/javascript-promise-leaks-memory.html
34 Upvotes

14 comments sorted by

2

u/[deleted] Oct 24 '17 edited Oct 24 '17

Using promise like that is asking to get beaten with a highly lethal stick to begin with, don't do that and you will be safe ?

BTW isn't that just plain bloating and not memory leak ?

2

u/eggn00dles Oct 24 '17

in recursive functions which people dont use anyway because js doesnt support tco? oh. im so concerned.

2

u/zlumer Oct 23 '17

But it promised not to leak!

1

u/[deleted] Oct 23 '17

Is using Observable (since they're cancelable) any better ?

2

u/[deleted] Oct 23 '17

[removed] — view removed comment

9

u/eggn00dles Oct 23 '17

its part of Microsoft's initiative to make web development as painful as working with dotnet. see TypeScript for reference.

0

u/DanielFGray Oct 24 '17

Observables are great what are you on about? I mean the docs for Rx admittedly aren't the best, but there are other implementions (kefir, bacon, most) if you prefer.

Observables are not a Microsoft thing.

1

u/DanielFGray Oct 24 '17

Observables are another pattern for dealing with async. They provide a somewhat similar API to what arrays provide, in that you can call map filter reduce etc on them, which act on the events emitted.

The biggest difference between promises and observables is that a promise will only resolve once and return a single value, whereas observables can emit many values over time.

You can use observables to represent click events, websocket events, pretty much anything.

I mentioned a few implementions below, besides just RxJS, but there is an official proposal for them to be added to the spec.

1

u/[deleted] Oct 23 '17 edited Oct 23 '17

Observable is primarily a pattern. But if you want to you use it you need to use Rx which as implementations in many languages ( Js but also java, python etc..).

Edit here is a presentation by Ben Lesh about it explaining difference s between Observables and promises.

0

u/DanielFGray Oct 24 '17

if you want to use [observables] you need to use Rx

That's not true at all. There's an official proposal for them (currently stage 1 I believe), there's also probably a half dozen other implementations: kefir, bacon, and most, off the top of my head.

1

u/[deleted] Oct 24 '17

So stage 1 is a proposal so I need to use a library. And, correct me if I'm wrong but any of the other library you listed may work but none have the same community adoption that Rx has.